Date.prototype.getUTCFullYear()
Returns the four-digit year of a date according to universal time rather than local time.
getUTCFullYear()- Added in JavaScript ES1
Return value
numberAn integer representing the year for the given date according to universal time. For dates between the years 1000 and 9999 this is a four-digit number. Returns NaN if the date is invalid.
getUTCFullYear() reads the year from the date as it appears in UTC. Its local-time twin, getFullYear(), reads the same instant as it appears on the machine running the code — and near a year boundary those two answers differ.
When to reach for it
- Any time the output must be identical on every machine: log lines, filenames, cache keys, database strings.
- Building a date string by hand alongside
getUTCMonth()andgetUTCDate(). - Bucketing records into calendar years on a server whose time zone you do not control.
What trips people up
The year boundary is the classic bug. An instant at 2024-12-31T23:30:00Z is still 2024 in UTC, but already 2025 for anyone in UTC+1 — mixing getFullYear() in one place and getUTCFullYear() in another produces reports that are off by a year for a few hours each December.
Note the name: getUTCFullYear() returns the absolute year, unlike the legacy getYear(), which returned the year minus 1900 and should never be used. There is no upper cap at four digits either — a date past the year 9999 returns five digits, and years before 1 return negative numbers.
Example
When to use it
- Stamp a log file or export name with a year that is the same everywhere
- Assemble an ISO date string by hand from its UTC parts
- Group analytics rows into calendar years independently of server locale
- Check whether a stored date falls in a leap year
Frequently asked questions
What is the difference between getFullYear() and getUTCFullYear()?
getFullYear() reports the year in the machine's local time zone, while getUTCFullYear() reports it in UTC. They disagree for any instant within a few hours of midnight on 31 December, so pick one and use it consistently.
Why does getUTCFullYear() return a different year than the date string I passed in?
Because the string carried a non-UTC offset. "1975-12-31T23:15:30-11:00" is 1 January 1976 in UTC, so the UTC year is 1976 even though the text reads 1975.
Should I use getYear() instead?
No — getYear() is a deprecated legacy method that returns the year minus 1900, so 2024 comes back as 124. Use getUTCFullYear() or getFullYear(), which return the absolute year.
More examples
Build a stable YYYY-MM-DD string
The hand-built string matches the first ten characters of toISOString() exactly, which is the point: UTC getters give the same output on every machine. Note the +1 on the month, which is zero-based.
const t = new Date("2024-03-09T22:30:00Z");
const iso =
`${t.getUTCFullYear()}-` +
`${String(t.getUTCMonth() + 1).padStart(2, "0")}-` +
`${String(t.getUTCDate()).padStart(2, "0")}`;
console.log(iso);
console.log(t.toISOString().slice(0, 10));
console.log(iso === t.toISOString().slice(0, 10));Leap year check from a stored date
Prints 2024 true, 1900 false, 2000 true — the century rule in action. Reading the year in UTC means the answer does not flip for users whose local date has already rolled over.
function isLeap(year) {
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
}
for (const iso of ["2024-02-29T00:00:00Z", "1900-06-01T00:00:00Z", "2000-06-01T00:00:00Z"]) {
const y = new Date(iso).getUTCFullYear();
console.log(y, isLeap(y));
}
Discussion