Conversion timestamp format

A: Time stamp transfer: methods javascript timestamp obtained four are time objects by instantiating new Date () to get the current timestamp further

1.var timestamp1 = Date.parse (new Date ()); // Results: 1477808630000 do not recommend this approach, the value is converted milliseconds to 000

console.log(timestamp1);

2.var timestamp2 = (new Date ()) valueOf (); // Results: 1477808630404 accurate time stamp values ​​valueOf () function returns the value of the original object

console.log(timestamp2);

3.var timestamp3 = new Date () getTime (); // Results: 1477808630404 obtain the current time milliseconds directly through prototyping, accurate

console.log(timestamp3);

4.var timetamp4 = Number (new Date ()); // Result: 1477808630404, time values ​​into a number of types, i.e., a time stamp

Guess you like

Origin www.cnblogs.com/NZ12/p/12502821.html