Today in the work to get to the time to convert to timestamp, at a time do not know how to use, so have to find information, here specially to make a note.
1. Convert the date to a timestamp.
To convert a date to a timestamp, you first get to the date, where you can specify the date directly, or use the current date. To get the current date, we can use the new date () to get it. directly on the code.
//(1), convert the current date to a timestamp. varnow =NewDate (); Console.log (Now.gettime ())//converts the current date to a timestamp, and the GetTime () method returns the number of milliseconds from January 1, 1970. //(2), converts the specified date to a timestamp. vart = "2017-12-08 20:5:30";//months, days, hours, minutes, seconds if not two digits can be 0. varT =NewDate (t);//converts the specified date to the standard date format. Fri Dec 20:05:30 gmt+0800 (China Standard Time)Console.log (T.gettime ())//Converts the converted standard date to a timestamp.
2. Convert the timestamp to a date.
var t = 787986456465; // when the argument is a number, then this parameter is the timestamp, which is treated as a millisecond, creating a time-date object that is specified in milliseconds from January 1, 1970. Console.log (new// Wed Dec 1994 13:07:36 gmt+0800 (China Standard Time)var t2 = "2017-5-8 1 2:50:30 "; Console.log (new/ Mon may 12:50:30 gmt+0800 (China Standard Time)var t3 = "2017-10-1"; Console.log (new/ Sun Oct 00:00:00 gmt+0800 ( China standard Time) No timing seconds, the default is converted to 00:00:00
JS timestamp and time-date conversion between