set year in javascript code example Example: set year in javascript var d = new Date(); d.setFullYear(2020);