Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript setUTCFullYear() Method

JavaScript setUTCFullYear() Method

Date Object Reference JavaScript Date object

Example

Set the year to 1992:

var d = new Date();

d.setUTCFullYear(1992);

d Output result:

Try it »


Definition and Usage

The setUTCFullYear() method is used to set the year according to Universal Time (UTC).

**Note:** Coordinated Universal Time, also known as Universal Time, Universal Standard Time, or International Coordinated Time, abbreviated as UTC (Universal Coordinated Time).

**Note:** UTC time is the same as GMT (Greenwich) time.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the setUTCFullYear() method.


Syntax

Date

.setUTCFullYear(

year

,

month

,

day

)

Parameter value

Parameters Description
year Required. The value to set for the year field of dateObject.
This parameter should be a full year including the century, such as 1999, not just an abbreviated year value such as 99.
month Optional. The value to set for the month field of 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 next year
  • 13 is the second month of the next year.
  • | | *day* | Optional. The value to set for the day field of dateObject. Expressed in universal time.

    This parameter is an integer between 1 and 31:

    If the current month has 31 days:

    If the current month has 30 days:

    |

    Return Value

    Type Description
    Number The number of milliseconds from January 1, 1970 to 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);

    d Output result:

    Try it »

    Example

    Set the date to 6 months earlier according to Universal Time (UTC):

    var d=new Date();

    d.setUTCFullYear(d.getUTCFullYear,d.getUTCMonth()-6);

    d Output result:

    Try it »


    Date Object Reference JavaScript Date object