JavaScript setUTCFullYear()Method

Date 对象参考手册JavaScript Date Object

Example

Set the year to 1992:

var d = new Date();
d.setUTCFullYear(1992);

dOutput:


Try it yourself »

Definition and Usage

The setUTCFullYear() method sets the year according to universal time (UTC).

Tip:Coordinated Universal Time, also known as World Unified Time, World Standard Time, International Coordinated Time, abbreviated as UTC ( Universal Coordinated Time).

Tip:UTC time is GMT (Greenwich) time.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the setUTCFullYear() method.


Syntax

Date.setUTCFullYear(year,month,day)

Parameter Values

Parameter Description
year Required. The value of the year field to be set for the dateObject.
This parameter should be a complete year including the century value, such as 1999, not just an abbreviated year value, like 99.
month Optional. The value of the month field to be set for the dateObject. Expressed in universal time.

This parameter is an integer between 0 and 11:

  • -1 is the last month of the previous year
  • 12 is the first month of the next year
  • 13 is the second month of the next year
day Optional. The value of the day field to be set for the dateObject. Expressed in universal time.

This parameter is an integer between 1 and 31:

  • 0 is the last hour of the previous month.
  • -1 is one hour before the last hour of the previous month.

If the current month has 31 days:

  • 32 is the first day of the next month

If the current month has 30 days:

  • 32 is the second day of the next month

Return Value

Type Description
Number The number of milliseconds between January 1, 1970 and the adjusted date.

Technical Details

JavaScript Version: 1.3


More Examples

Example 2

Set the date to October 3, 2020:

var d = new Date();
d.setUTCFullYear(2020,10,3);

dOutput:


Try it yourself »

Example

Set the date to 6 months ago according to universal time (UTC):

var d=new Date();
d.setUTCFullYear(d.getUTCFullYear,d.getUTCMonth()-6);

dOutput:


Try it yourself »


Date 对象参考手册JavaScript Date Object

Other Extensions