JavaScript Date toISOString() method - JavaScript Tutorial

JavaScript Date toISOString() method

BLUF: This tutorial on JavaScript Date toISOString() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Date toISOString() method

Understanding JavaScript Date toISOString() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The toISOString method in JavaScript provides a string representation of a Date object. The string produced adheres to the simplified extended ISO format and consistently contains either 24 or 27 characters.

Syntax

The syntax for the toISOString method is illustrated as follows:

Example

dateObj.toISOString()

Return

A Date object in the form of ISO string.

JavaScript Date toISOString method example

In this section, we will explore the toISOString method by examining a variety of examples.

Example 1

Let us examine a scenario where we retrieve the current date formatted as an ISO string.

Example

<script>

var date=new Date();

document.writeln(date.toISOString());

</script>

Output:

Output

2018-08-09T13:01:38.116Z

Example 2

Let's examine an example that demonstrates how to transform a given Date object into the format of an ISO string.

Example

<script>

var date=new Date(1947, 7, 15, 20, 22, 10);

document.writeln(date.toISOString());

</script>

Output:

Output

1947-08-15T14:52:10.000Z

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience