JavaScript .toISOString()
Published Jun 2, 2022
Contribute to Docs
The .toISOString() method returns a string representation of a date in an ISO 8601-compliant format according to universal time (UTC).
Syntax
date.toISOString();
The string returned from the .toISOString() method will always be 24 or 27 characters long such as YYYY-MM-DDThh:mm:ss.sssZ or ±YYYYYY-MM-DDThh:mm:ss.sssZ, respectively.
Example
In the example below, today’s date is declared and stored in a variable. It is then invoked against the .toISOString() method:
const today = new Date();console.log(today.toISOString());
The snippet above will output something similar to the following:
2022-04-22T18:12:21.369Z
Codebyte Example
The following example further demonstrates how the .toISOString() method is used:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Learn how to build back-end web APIs using Express.js, Node.js, SQL, and a Node.js-SQLite database library.
- Includes 8 Courses
- With Certificate
- Beginner Friendly.30 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours