Javascript Date setUTCFullYear(year) sets the year of the UTC date.
The year must be given with four digits (2019 instead of just 19).
dateObj.setUTCFullYear(yearValue[, monthValue[, dayValue]])
yearValue
- An integer specifying the numeric value of the year, for example, 1995.monthValue
Optional. An integer between 0 and 11 representing the months January through December.dayValue
Optional. An integer between 1 and 31 representing the day of the month. If you specify the dayValue
parameter, you must also specify the monthValue
.The number of milliseconds between 1 January 1970 00:00:00 UTC and the updated date.
If a parameter is outside of the expected range, setUTCFullYear()
updates the date accordingly.
For example, if you specify 15 for monthValue
, the year is incremented by 1 (yearValue
+ 1), and 3 is used for the month.
var d = new Date(); console.log(d);//from w ww.j av a 2s . c o m d.setUTCFullYear(1997); console.log(d);
Set the date to November 3, 2020:
var d = new Date(); d.setUTCFullYear(2020, 10, 3);//ww w .ja v a 2 s . c o m console.log(d);
Set the date to six months ago, UTC time:
var d = new Date(); d.setUTCFullYear(d.getUTCFullYear(), d.getUTCMonth() - 6); console.log(d);// w w w.j a v a 2s. co m