JavaScript toISOString() | Get the Date as String based on ISO Standard

The JavaScript toISOString() method is used to get the date as a string based on the ISO (International Organization for Standardization) standard. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <p id="xyz"></p>

   <script>
      const d = new Date();
      let dateISO = d.toISOString();
      document.getElementById("xyz").innerHTML = dateISO;
   </script>

</body>
</html>
Output

Please note: The ISO date format is YYYY-MM-DDTHH:mm:ss.sssZ where:

JavaScript toISOString() Syntax

The syntax of toISOString() method in JavaScript is:

x.toISOString()

where x must be an object of the Date() constructor.

The toISOString() method returns a string representing both the date and the time based on ISO standard.

JavaScript Online Test


« Previous Tutorial Next Tutorial »