The getTime() method returns the number of milliseconds between midnight of January 1, 1970 and the date object.
The getTime() method returns the number of milliseconds between midnight of January 1, 1970 and the date object.
Date.getTime()
None
A Number, representing the number of milliseconds since midnight January 1, 1970
Return the number of milliseconds since 1970/01/01:
//The internal clock in JavaScript starts at midnight January 1, 1970. //display the number of milliseconds since midnight, January 1, 1970. var d = new Date(); var n = d.getTime(); console.log(n);/* w w w .j a v a2 s . c om*/
Calculate the number of years since 1970/01/01:
//calculate the number of years since midnight, January 1, 1970. 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); console.log(y);//from w ww . j a v a 2 s .com