Date toString() Method - Javascript Date

Javascript examples for Date:toString

Description

The toString() method converts a Date object to a string.

This method is called whenever a Date object needs to be displayed as a string.

Parameters

None

Return Value:

A String, representing the date and time as a string

The following code shows how to Convert a Date object to a string:

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  w  w  w  . j  a  va  2 s. c  om*/
    var d = new Date();
    var n = d.toString();
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials