JavaScript Date toISOString() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Date

Definition

Date.prototype.toISOString() returns a string for this instant in the simplified ISO 8601 date-time format — always in UTC, ending with Z (for example "2011-10-05T14:48:00.000Z"). It is read-only and does not change the Date.

Remember
date.toISOString()

→ "2011-10-05T14:48:00.000Z"   (UTC, always ends with Z)
→ RangeError                   (if the Date is invalid)

Format (24 chars for common years):
  YYYY-MM-DD T HH:mm:ss.sss Z

toDateString()  → local date only (no Z)
toJSON()        → usually same as toISOString()
toUTCString()   → UTC text, different layout

Syntax

Call date.toISOString. Start with this line.

JavaScript
date.toISOString()
CallWhat it does
date.toISOString()Primary signature.
date.toISOString(...)Call with the arguments your case needs.

Built into JavaScript. Call toISOString(...) on a Date instance — no import required.

Library declarations
JavaScript
date.toISOString()

Parameters

This method has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*The value returned by date.toISOString().

JavaScript Examples

Example 1 — Basic toISOString() Output

Serialize a UTC instant built with Date.UTC.

JavaScript
const date = new Date(Date.UTC(2026, 2, 15, 12, 0, 0));

console.log(date.toISOString());
// "2026-03-15T12:00:00.000Z"
Try It Yourself

How It Works

  1. Build a UTC instant. Date.UTC(2026, 2, 15, 12, 0, 0) is noon on Mar 15, 2026 in UTC (month index 2).
  2. Wrap it in a Date. new Date(...) stores that millisecond instant.
  3. Serialize. toISOString() returns the portable …Z string.
  4. No side effects. The Date is unchanged; only a string is returned.

Example 2 — UTC Date Only with slice(0, 10)

Take the YYYY-MM-DD prefix from the ISO string (UTC calendar day).

JavaScript
const event = new Date("05 October 2011 14:48 UTC");

console.log(event.toISOString());
// "2011-10-05T14:48:00.000Z"

console.log(event.toISOString().slice(0, 10));
// "2011-10-05"
Try It Yourself

How It Works

  1. Parse a UTC string. The constructor stores one absolute instant.
  2. Get the full ISO form. toISOString() includes time and Z.
  3. Keep the date prefix. slice(0, 10) cuts "YYYY-MM-DD".
  4. Remember UTC. Near local midnight, this day can differ from toDateString().

Example 3 — Guard Against RangeError

Check validity before calling toISOString() on untrusted input.

JavaScript
const bad = new Date("not-a-date");

if (Number.isNaN(bad.getTime())) {
  console.log("Bad input");
} else {
  console.log(bad.toISOString());
}
// without the guard: RangeError: Invalid time value
Try It Yourself

How It Works

  1. Create an invalid Date. new Date("not-a-date") has a NaN time value.
  2. Detect it early. Number.isNaN(bad.getTime()) is true.
  3. Skip the call. Log a clear message instead of throwing.
  4. Why it matters. Unchecked toISOString() throws RangeError and can crash a request handler.

Browser & Runtime Support

Date.prototype.toISOString() has been in JavaScript since ES5. It is Baseline and works in every modern browser and Node.js — no polyfill needed for current targets.

✓ Baseline · ES5

Date.prototype.toISOString()

Supported in Chrome, Firefox, Safari, Edge, Internet Explorer 9+, and all modern Node.js versions.

99% Universal API
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Date.toISOString() Excellent

Bottom line: Safe for APIs and modern runtimes. Always validate invalid dates before calling. See also the MDN toISOString() reference.

Frequently Asked Questions

A UTC string in the simplified ISO 8601 date-time format: YYYY-MM-DDTHH:mm:ss.sssZ (for example "2011-10-05T14:48:00.000Z"). The trailing Z means Coordinated Universal Time.
Always UTC. The same instant is expressed in Coordinated Universal Time, regardless of the machine’s local timezone.
toISOString() returns a full UTC instant with time and Z. toDateString() returns a local calendar date string with no time and no Z.
toISOString() throws a RangeError ("Invalid time value"). Validate first with Number.isNaN(date.getTime()), or wrap the call in try/catch.
Use date.toISOString().slice(0, 10). That is the UTC calendar date of the instant — near midnight it can differ from the local calendar day.
No. It is read-only — it returns a new string and leaves the Date unchanged.

Next: toJSON()

Learn how Date values become ISO strings inside JSON.stringify.

toJSON() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful