Home >Web Front-end >JS Tutorial >JavaScript code to get the current timestamp_time and date
JavaScript to get the current timestamp:
The first method:
Use new Date().getTime() method in javascript
IE8 and above versions can be used directly using the Date.now() method
//Versions below IE8
if (!Date.now) {
Date.now = function() { return new Date().getTime(); };
}
jQuery gets timestamp $.now()
var timestamp = $.now();
The following are additions from other netizens:
JavaScript to get the current timestamp:
First method:
var timestamp = Date.parse(new Date());
Result: 1280977330000
Second method:
var timestamp = (new Date()).valueOf();
Result: 1280977330748
The third method:
var timestamp=new Date().getTime();
Result: 1280977330748
The first method: the timestamp obtained is to change the milliseconds to 000 for display,
The second and third methods obtain the timestamp of the current millisecond.