Date now() Method - Javascript Date

Javascript examples for Date:now

Description

The now() method returns the number of milliseconds since January 1, 1970 00:00:00 UTC.

Parameters

None

Return Value:

A Number, representing the number of milliseconds since midnight January 1, 1970

The following code shows how to use the number of milliseconds since 1970/01/01 to Calculate the number of years since 1970/01/01:

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.  ja v  a 2s . c o  m*/
    var minutes = 1000 * 60;
    var hours = minutes * 60;
    var days = hours * 24;
    var years = days * 365;
    var t = Date.now();

    var y = Math.round(t / years);

    document.getElementById("demo").innerHTML = y;
}
</script>

</body>
</html>

Related Tutorials