Problem background: Want to turn a time directly into a string format
A tolocalestring () is found by checking the API to convert the Date object to a string based on the local time format
New Date (). tolocalestring (); // "2018/5/31 pm 1:43:06"
But the default is 12-hour system, will take this morning afternoon, so certainly do not need, continue to check, found can be configured
var New 3600000 ;( New Date (ss). tolocalestring (' Chinese ', {hour12:false})). Replace (/\//G, '-'); // "2018-5-31 14:40:32"
This turns into the format I need.
JS's Date object method, you can see: JavaScript Date Object
1,JS get the current timestamp method
var timestamp1 = Date.parse (new Date ()); var timestamp2 = (new Date ()). ValueOf (); var New Date (). GetTime (); Console.log (Timestamp1,timestamp2,timestamp3) // vm140:4 1527745698000 1527745698616 1527745698616
The first: The time stamp obtained is precision to the second level, the millisecond is changed to 000 display;
The second and third is the precision to the millisecond level, which gets the timestamp of the current millisecond.
var New Date (); var newDay2 = Date.parse (new Date ()); var newDay3 = +new Date (); Console.log (number (newDay1), newday2,newday3)// vm160:4 1527745994726 1527745994000 1527745994726
The first and third, the timestamp returned by the method using the numeric object, is exactly the millisecond,
The second Date object's Date.parse () method is only accurate to the second, the latter three bits are filled with 0, so the first one is recommended
2. Convert Timestamps to date objects
New Date (1527745994726)//Thu 2018 13:53:14 gmt+0800 (China Standard Time)
Time processing in javascript: Convert timestamp or Time object to string format