Date toString() Method - Javascript Date

Javascript examples for Date:toString


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.



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>

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

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

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;


Related Tutorials