UNB/ CS/ David Bremner/ teaching/ cs2613/ books/ mdn/ Reference/ Global Objects/ Date/ Date.prototype.toISOString()

The toISOString() method of Date instances returns a string representing this date in the date time string format, a simplified format based on ISO 8601, which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always UTC, as denoted by the suffix Z.

Syntax

toISOString()

Parameters

None.

Return value

A string representing the given date in the date time string format according to universal time. It's the same format as the one required to be recognized by Date.parse.

Exceptions

Examples

Using toISOString()

const d = new Date(0);

console.log(d.toISOString()); // "1970-01-01T00:00:00.000Z"

Specifications

Browser compatibility

See also