the parseInt ( new new a Date () the getTime () / 1000.) ;, or Date.parse ( new new a Date ()) / 1000; . 1 , converting the current date stamp. var now = new new a Date (); the console.log (now.getTime ()) // converts the current date stamp, getTime () method returns the number of milliseconds between from January 1, 1970. May also be used + now, the effect is the same now.getTime () // (2), to convert the specified date stamp. var T = "2017-12-08 20 is:. 5: 30"; // month, day, hour, minute, second two digits may not be less than if the band of 0. The var T = new new a Date (T); // the specified date into a standard date format. Fri Dec 08 2017 20:05:30 GMT + 0800 ( China Standard Time) console.log (T.getTime ()) // converts standard date back to a timestamp. 2 , the timestamp into a date. var t = 787 986 456 465; // When the parameter is a number, then this parameter is the time stamp, is considered milliseconds, creation date and time specified object is a millisecond from 1 January 1970. the console.log ( new new a Date (T)) // Wed On Dec 1994 13:07:36 GMT + 21 is 0800 (China Standard Time) var T2 = "2017-5-8 12:50:30" ; the console.log ( new new DATE (T2)) // Mon On May 08 12:50:30 GMT 2017 + 0800 (China standard time) var T3 = "2017-10-1" ; the console.log ( new new DATE (T3)) // the Sun On Oct 01 2017 00:00:00 GMT + 0800 (China standard time) every minute is not set, the default converted 00:00:00 3 the date stamp is converted into the specified format of the encapsulation method: // formatted date, moon , day, hour, minute, second two digits to ensure that function = formatNumber (n-) { n- n.toString () return ? n-[. 1] n-: '0' + n-; } // parameter number milliseconds timestamp, format need be converted into date format function FormatTime (number, format) { the let Time = new new DATE (Number) the let newArr = [] the let formatArr = [ 'the Y', 'm', 'D', 'H', 'm', 'S' ] newArr.push (time.getFullYear ()) newArr.push (formatNumber (time.getMonth () +. 1 )) newArr.push (formatNumber (time.getDate ())) newArr.push (formatNumber (time.getHours ())) newArr.push (formatNumber (time.getMinutes ()) ) newArr.push (formatNumber (time.getSeconds ())) for (the let I in newArr) { the format = format.replace (formatArr [I], newArr [I]) } return the format; } if necessary to call the method described above, using formatTime ( 1,545,903,266,795, 'on the Y D m dated May h: m: s'), or formatTime (1545903266795, 'YMD h: m: s') to
js take several seconds of the current time stamp
Guess you like
Origin www.cnblogs.com/hermitks/p/11230052.html
Recommended
Ranking