JavaScript tutorial:
getUTCFullYear method

 

Applies to: Date Object

The getUTCFullYear menthod is use to get the year value in a Date object using Universal Coordinated Time (UTC).

Syntax

objDate.getUTCFullYear()

Return

Returns the year value in a Date object using UTC.

Example

To get the year using local time, use the getFullYear method.

The getUTCFullYear method returns the year as an absolute number. This avoids problems with dates occurring at the end of the 20th century.

The following example illustrates the use of the getUTCFullYear method:

function UTCDate()
{
    var d, s = "Today's UTC date is: ";
    d = new Date();
    s += (d.getUTCMonth() + 1) + "/";
    s += d.getUTCDate() + "/";
    s += d.getUTCFullYear();
    return(s);
}

alert(UTCDate());

To run the code above, paste it into JavaScript Editor, and click the Execute button


See also: Date Object Methods, getFullYear Method, setFullYear Method, setUTCFullYear Method