JavaScript obtains the implementation code of the current timestamp. For more information, see. JavaScript to get the current timestamp:
Method 1:
The Code is as follows:
Var timestamp = Date. parse (new Date ());
Result: 1280977330000
Method 2:
The Code is as follows:
Var timestamp = (new Date (). valueOf ();
Result: 1280977330748
The above code gets the number of milliseconds that have elapsed since midnight, January 1, January 1, 1970. The difference between the two is that, in the first method, the millisecond bit is zero, that is, only the number of milliseconds accurate to the second
As shown in the following figure, the specific time corresponding to the unix timestamp is returned:
The Code is as follows:
Var time = '20140901 ';
// The key is to multiply by 1000, because the time is relative to the start of 1970, so after multiply by 1000, it will be converted to the current time.
Var real_time = new Date (time) * 1000;
Document. write (real_time );
The code is easy to convert the timestamp.
Use the new Date (). getTime () method in javascript
For IE8 or later versions, you can use the Date. now () method directly.
// IE8 or earlier versions
If (! Date. now ){
Date. now = function () {return new Date (). getTime ();};
}
JQuery get timestamp $. now ()
Var timestamp = $. now ();
The following is a supplement from other netizens:
JavaScript to get the current timestamp:
Method 1:
Var timestamp = Date. parse (new Date ());
Result: 1280977330000
Method 2:
Var timestamp = (new Date (). valueOf ();
Result: 1280977330748
Method 3:
Var timestamp = new Date (). getTime ();
Result: 1280977330748
First, the acquired timestamp is changed to 000 for display in milliseconds,
The second and third types obtain the timestamp of the current millisecond.