myDate.getFullYear() in ECMAScript 262
Return the four-digit year in the local timezone.
- Return Type
- Number
Description
This method is the replacement for the ill-designed getYear()
method which returned the year number - 100.
var bday = new Date("12/31/2003");
var year = bday.getYear(); // ** 103 .. totally useless :)
var year = bday.getFullYear(); // ** 2003
To get a two-digit version of the year (did Y2k teach us nothing?!) convert it to a string and use String.slice()
:
var bday = new Date("12/31/2003");
var twoDigitYear = bday.getFullYear().toString().slice(-2); // ** "03"