Javascript Reference - JavaScript toISOString() Method








toISOString() Method return a Date object as a String, using the ISO standard.

The standard is called ISO-8601 and the format is: YYYY-MM-DDTHH:mm:ss.sssZ

Browser Support

toISOString() Yes 9.0 Yes Yes Yes

Syntax

dateObject.toISOString();

Parameters

None.





Return Value

A string, representing the date and time using the ISO standard format.

Example


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--   www  . j  a  v  a2 s.  c  o m-->
    var d = new Date();
    var n = d.toISOString();
    document.getElementById("demo").innerHTML = n;
}
</script>
</body>
</html>

The code above is rendered as follows: