Gets the current timestamp (in s) of var timestamp = Date.parse (new Date ()), timestamp = timestamp/1000;//The current timestamp is: 1403149534console.log (" The current timestamp is: "+ timestamp);//Gets the timestamp of a time format var stringtime =" 2014-07-10 10:21:12 "; var timestamp2 = Date.parse (New Date (Stringti me); timestamp2 = timestamp2/1000;//2014-07-10 10:21:12 timestamp: 1404958872 console.log (StringTime + "timestamp:" + TIMESTAMP2 )//Convert current time to time format string var Timestamp3 = 1403058804;var newdate = new Date () newdate.settime (Timestamp3 * +);//Wed June 18 2 014 Console.log (Newdate.todatestring ());//Wed, June 02:33:24 GMT Console.log (newdate.togmtstring ());// 2014-06-18t02:33:24.000zconsole.log (Newdate.toisostring ());//2014-06-18t02:33:24.000z Console.log ( Newdate.tojson ());//June 18, 2014 Console.log (newdate.tolocaledatestring ());//June 18, 2014 Morning 10:33:24 Console.log ( Newdate.tolocalestring ());//Morning 10:33:24 Console.log (newdate.tolocaletimestring ());//Wed June 10:33:24 gmt+0800 (China Standard Time) Console.log (newdate.tostring ());//10:33:24 gmt+0800 (China Standard Time) Console.loG (newdate.totimestring ());//Wed, June 02:33:24 GMTconsole.log (newdate.toutcstring ());D Ate.prototype.format = function (format) {var date = {"m+": This.getmonth () + 1, "d+": this.getdate (), "H +": this.gethours (), "m+": This.getminutes (), "s+": This.getseconds (), "q+": Math.floor ((This.getmonth () + 3)/3), "S+": This.getmilliseconds ()}; if (/(y+)/i.test (format)) {format = Format.replace (regexp.$1, (this.getfullyear () + "). substr (4-regexp.$1 . length)); } for (var k in date) {if (New RegExp ("(" + K +) "). Test (format)) {format = form At.replace (regexp.$1, regexp.$1.length = = 1? Date[k]: ("XX" + date[k]). substr (("" + date[k]). length)); }} return format;} Console.log (Newdate.format (' Yyyy-mm-dd h:m:s '));
JS timestamp and date cross-transfer