Home »
JavaScript
Date getTime() method with example in JavaScript
JavaScript Date getTime() method: Here, we are going to learn about the getTime() method of Date class with Example in JavaScript.
Submitted by IncludeHelp, on March 04, 2019
JavaScript Date getTime() method
getTime() method is a Date's class method and it is used to get the time in milliseconds from 1st January 1970.
It accepts nothing as the parameter and returns a total number of milliseconds from 1st January 1970 to till now.
Syntax
var dt = new Date();
dt.getTime();
Sample Input/Output
Input:
var dt = new Date();
dt.getTime();
Output:
1551709453576
JavaScript code to get the time in milliseconds using getTime() method
<html>
<head><title>JavaScipt Example</title></head>
<body>
<script>
var dt = new Date(); //Date constructor
var timeinMs = dt.getTime(); //getting time in milliseconds
//printing time
document.write("Current time is (in milliseconds): " + timeinMs);
</script>
</body>
</html>
Output
Current time is (in milliseconds): 1551709453576
JavaScript Date Object Methods »