Date.UTC, Date.prototype.toISOString, Date.prototype.getUTCHours
Date.UTC(year, monthIndex, date, hours, minutes, seconds, ms)
new Date(value)
date.toISOString()
date.getUTCFullYear()
date.getUTCMonth()Build a Date from an explicit UTC timestamp or a Z-suffixed ISO string, then read UTC fields. The month index is 0-based.
| Parameter | Description |
|---|---|
year, monthIndex, date, hours, minutes, seconds, ms | Date.UTC takes a year and a 0-based month, then optional day and time fields, all interpreted as UTC. day defaults to 1; the time fields default to 0. |
value | A millisecond timestamp, or an ISO-8601 string. A string with a Z or numeric offset is UTC. A date-only YYYY-MM-DD string is also specified as UTC midnight. A date-time string without an offset is specified as local time. |
Returns: Date.UTC returns a number of milliseconds. toISOString returns a string such as 2026-01-01T15:04:05.006Z. The getUTC* methods return numbers; getUTCMonth returns 0 for January.
Throws
RangeError— toISOString throws if the Date is invalid, for example after new Date("not a date"). The next example shows how to detect that case without calling toISOString.
- These outputs were measured in Node.js 22. They do not exercise the host local timezone.
- Date.parse and the Date constructor treat a complete ISO-8601 string with a Z or numeric offset, and a date-only YYYY-MM-DD string, as UTC. ECMAScript defines that date-only form as UTC midnight. A date-time string without an offset is specified as local time, so converting it to UTC depends on the host timezone and is not asserted here. Non-standard date strings, such as "01/01/2026", are implementation-defined and are not used as expected output.
- new Date() with no arguments uses the current time and is not deterministic, so it is not used here.
const utc = new Date(Date.UTC(2026, 0, 1, 15, 4, 5, 6));
console.log(utc.toISOString());
console.log(
utc.getUTCFullYear(),
utc.getUTCMonth(),
utc.getUTCDate(),
utc.getUTCHours(),
utc.getUTCMinutes(),
utc.getUTCSeconds(),
utc.getUTCMilliseconds(),
);
const parsed = new Date("2026-01-01T15:04:05.006Z");
console.log(parsed.toISOString(), parsed.getTime() === utc.getTime());
console.log(new Date("2026-01-01").toISOString());Expected output
2026-01-01T15:04:05.006Z
2026 0 1 15 4 5 6
2026-01-01T15:04:05.006Z true
2026-01-01T00:00:00.000ZRelated: Intl.DateTimeFormat with a timeZone