setFullYear()
sets the year of a date.
setFullYear()
can also set month and day.
Set the date to six months ago:
const d = new Date();
d.setFullYear(d.getFullYear(), d.getMonth() - 6);
Try it Yourself »
setFullYear()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
Date.setFullYear(
year,
month,
day)
year | Required. The year. Negative values are allowed. |
month | Optional. The month (0 to 11). Higher and lower values are handeled with date maths:
|
day | Optional. The day (0 to 31). Higher and lower values are handeled with date maths:
|
A number. Number of milliseconds between the date and January 1, 1970 00:00:00 UTC. |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!