//Gets the current timestamp (in s)vartimestamp = Date.parse (NewDate ()); timestamp= timestamp/1000;//the current timestamp is: 1403149534Console.log ("Current timestamp is:" +timestamp);//gets the timestamp of a time formatvarStringTime = "2014-07-10 10:21:12";varTIMESTAMP2 = Date.parse (NewDate (StringTime)); TIMESTAMP2= timestamp2/1000;//the timestamp for 2014-07-10 10:21:12 is: 1404958872Console.log (StringTime + "timestamp is:" +timestamp2);//change the current time to a time format stringvarTimestamp3 = 1403058804;varNewdate =NewDate (); Newdate.settime (Timestamp3* 1000);//Wed JuneConsole.log (newdate.todatestring ());//Wed, June 02:33:24 GMTConsole.log (newdate.togmtstring ());//2014-06-18t02:33:24.000zConsole.log (newdate.toisostring ());//2014-06-18t02:33:24.000zConsole.log (Newdate.tojson ());//June 18, 2014Console.log (newdate.tolocaledatestring ());//June 18, 2014 morning 10:33:24Console.log (newdate.tolocalestring ());//Morning 10:33:24Console.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) {varDate = { "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(varKinchdate) { if(NewRegExp ("(" + K + ")"). Test (format)) {format= Format.replace (regexp.$1, regexp.$1.length = = 1? Date[k]: ("XX" + date[k]). substr ("" +Date[k]) (length)); } } returnformat;} Console.log (Newdate.format (' Yyyy-mm-dd h:m:s '));</script>
JavaScript timestamps and date strings are converted to each other