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>
   <p id="xyz"></p>

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


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

  • YYYY represents the full year
  • MM represents the month in 2-digits form. 0 will be added before the month number if the month number is from 1 to 9
  • DD represents the day of the month in 2-digit form, which will be from 01 to 31
  • T stands for Time (beginning of the time)
  • HH represents hours, which will be from 00 to 23
  • mm represents minutes, which will be from 00 to 59
  • ss represents seconds, which will be from 00 to 60. 60 is only used to denote an added leap seconds
  • sss represents milliseconds, which will be from 000 to 999
  • Z stands for zone designator

JavaScript toISOString() Syntax

The syntax of toISOString() method in JavaScript is:


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 »

Like/Share Us on Facebook 😋