How to use getTime in JavaScript
In this article, I will explain use of getTime() method in JavaScript date object.
JavaScript date getTime() method
-
getTime() method of date object returns the number of milliseconds or numeric value corresponding to the time and the specified date.
-
In getTime() method, The returned value is the number of milliseconds.
Syntax
Example
In the following example show to how the getTime() method can be used.
<!DOCTYPE html>
<html>
<body>
<h3 style="color:green">JavaScript getTime() Method Example</h3>
<p id="demo">Click For diaplay total years since midnight, January 1, 1989.</p>
<button onclick="myFunction()">Click</button>
<script type="text/javascript">
function myFunction() {
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);
var x = document.getElementById("demo");
document.write("Total Year is: " + y);
}
</script>
</body>
</html>
|
Output1

Output2

You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here