Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Date — timestamps and the UTC year

Date stores a timestamp. Learn how to read and change the UTC year, understand object mutation, and handle date normalization, including moving February 29 into a non-leap year.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

new Date(milliseconds)
new Date(isoString)
date.getUTCFullYear()
date.setUTCFullYear(year[, month[, day]])

Date is an ECMAScript built-in object storing milliseconds since 1970-01-01T00:00:00.000Z, or NaN for an invalid date. It does not store a time zone. Local methods interpret the same timestamp using the environment's time zone; UTC methods use UTC.

Date.prototype.getUTCFullYear() returns the full UTC year, or NaN for an invalid date. Date.prototype.setUTCFullYear(year[, month[, day]]) mutates the object and returns the resulting timestamp, not a Date object. Months use indexes 0–11, while days of the month start at 1. If the original date is valid, the method uses its current UTC month or day as an input for each corresponding omitted argument. Normalization can change the month and day in the result. If the result is valid, the UTC time of day stays unchanged.

The setter normalizes values: changing February 29 to a non-leap year produces March 1. A year of 0–99 is interpreted literally, unlike the multi-argument Date constructor. For an invalid date, the setter uses timestamp 0 as its starting point; invalid numeric arguments can still produce NaN.

The example uses an explicit Z and UTC methods so the result does not depend on the local time zone. It also checks that the returned timestamp matches the mutated object.

Examples

const date = new Date("2024-02-29T12:00:00.000Z");
console.log(date.getUTCFullYear());
const timestamp = date.setUTCFullYear(2025);
console.log(date.toISOString());
console.log(timestamp === date.getTime());

Result

2024
2025-03-01T12:00:00.000Z
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources