Date valueOf() Method - Javascript Date

Javascript examples for Date:valueOf

Description

The valueOf() method returns the primitive value of a Date object as the number of millisecond since midnight January 1, 1970 UTC.

Parameters

None

Return Value:

A Number, representing the number of milliseconds between the date object and midnight January 1, 1970 UTC

The following code shows how to return the primitive value of a Date object:

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  a  va  2  s . co  m*/
    var d = new Date();
    var n = d.valueOf();
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials