JavaScriptProgrammer'sReference

Given a time value, it is helpful to be able to compute a year number from it. The ECMA compliant implementations use the extrapolated Gregorian system to map days to years and compute a time relative to the reference date of 01-January-1970 UTC. From there the year number can be established.

All non-leap years have 365 days with the usual number of days in each month. Leap years have an extra day in February. The calculation shown below uses known leap years and non-leap years to adjust the day numbers and yield the day number of the first day of the given year, and then use that to work out the time in milliseconds when the year started: