JavaScript gets the current timestamp:
The first method:
var timestamp = (new Date());
Result: 1280977330000
The second method:
var timestamp = (new Date()).valueOf();
Result: 1280977330748
The above code will get the number of milliseconds starting from midnight on January 1, 1970. The difference between the two is that the millisecond bit of the first method is all zero, that is, the number of milliseconds that are precise to the seconds.
As shown in the title, return the specific time corresponding to the unix timestamp:
var time = '1278927966';
// The key is to multiply 1000, because the time starts relative to 1970, multiplying 1000 will transfer to the current time.
var real_time = new Date(time) * 1000;
(real_time);
The code is very simple to complete the conversion of timestamps.
Use the new Date().getTime() method in javascript
IE8 or above can be used directly using the() method
//IE8 or below version
if (!) {
= function() { return new Date().getTime(); };
}
jQuery gets timestamp $.now()
var timestamp = $.now();
The following are the additions from other netizens:
JavaScript gets the current timestamp:
The first method:
var timestamp = (new Date());
Result: 1280977330000
The second method:
var timestamp = (new Date()).valueOf();
Result: 1280977330748
The third method:
var timestamp=new Date().getTime();
Result: 1280977330748
The first type: the timestamp obtained is to change milliseconds to 000 display.
The second and third are to obtain the timestamp of the current millisecond.