Calculate the number of years since 1970/01/01: - Javascript Date

Javascript examples for Date:getTime

Description

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 ww w .  j  a va  2 s .  c  o  m
    var minutes = 1000 * 60;
    var hours = minutes * 60;
    var days = hours * 24;
    var years = days * 365;
    var d = new Date();
    var t= d.getTime();

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

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

</body>
</html>

Related Tutorials