JavaScript setFullYear () method
Definition and Usage
setFullYear () method is used to set the year.
This method can be used to set the month and day of the month.
Browser Support
All major browsers support setFullYear () method
grammar
Date.setFullYear( year , month , day )
Parameter Value
parameter | description |
---|---|
year | Required. It represents an integer of four years. Expressed in local time. |
month | Optional. It represents a number of the month. Expressed in local time. Between 0 and 11:
|
day | Optional. Day of the month value. Expressed in local time. Between 1 to 31:
If the month has 31 days:
If the month has 30 days:
|
return value
类型 | 描述 |
---|---|
Number | 1970年1月1日午夜至调整过日期的毫秒。 |
technical details
JavaScript version: | 1.3 |
---|
More examples
Examples
In this example, we will () to set the date by setFullYear to November 3, 2020:
var d=new Date();
d.setFullYear(2020,10,3);
d.setFullYear(2020,10,3);
d output:
try it"
Examples
Set the date six months ago:
var d=new Date();
d.setFullYear(d.getFullYear,d.getMonth()-6);
d.setFullYear(d.getFullYear,d.getMonth()-6);
d output:
try it"