Date toJSON() Method - Javascript Date

Javascript examples for Date:toJSON

Description

The toJSON() method converts a Date object into a string, formatted as a JSON date using ISO-8601 standard: YYYY-MM-DDTHH:mm:ss.sssZ

Parameters

None

Return Value:

A String, representing the date and time formatted as a JSON date

The following code shows how to return a Date object as a String, formatted as a JSON date:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  www  . j av  a  2 s .  c  o  m
    var d = new Date();
    var n = d.toJSON();
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials