1 //Gets the current timestamp (in s)2 vartimestamp = Date.parse (NewDate ());3timestamp = timestamp/1000;4Console.log ("Current timestamp is:" +timestamp);5 6 7 8 //gets the timestamp of a time format9 varStringTime = "2017-12-06 21:51:12";Ten varTIMESTAMP2 = Date.parse (NewDate (StringTime)); OneTIMESTAMP2 = timestamp2/1000; A //the timestamp for 2017-12-06 21:51:12 is: 1512568272 -Console.log (StringTime + "timestamp is:" +timestamp2); - the varTimestamp3 = 1512567397; - varNewdate =NewDate (); -Newdate.settime (Timestamp3 * 1000); - //Wed Dec + Console.log (newdate.todatestring ()); - //Wed, Dec 13:36:37 GMT + Console.log (newdate.togmtstring ()); A //2017-12-06t13:36:37.000z at Console.log (newdate.toisostring ()); - //2017-12-06t13:36:37.000z -Console.log (Newdate.tojson (). Replace (/:\d{1,2}$/, ")); - //2017-12-6 -Console.log (Newdate.tolocaledatestring (). Replace (/\/+/g, '-')); - //2017/12/6 pm 9:36:37 in Console.log (newdate.tolocalestring ()); - //Afternoon 9:36:37 to Console.log (newdate.tolocaletimestring ()); + //Wed Dec 21:36:37 gmt+0800 (China Standard Time) - Console.log (newdate.tostring ()); the //21:36:37 gmt+0800 (China Standard Time) * Console.log (newdate.totimestring ()); $ //Wed, Dec 13:36:37 GMTPanax NotoginsengConsole.log (Newdate.toutcstring ());
1 varNewdate =NewDate ();2Date.prototype.format =function(format) {3 varDate = {4"m+": This. GetMonth () + 1,5"D+": This. GetDate (),6"H +": This. GetHours (),7"m+": This. getminutes (),8"S+": This. getseconds (),9"q+": Math.floor (( This. GetMonth () + 3)/3),Ten"S+": This. Getmilliseconds () One }; A if(/(y+)/i.test (format)) { -Format = Format.replace (Regexp.$1, ( This. getFullYear () + "). substr (4-regexp.$1. length)); - } the 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; + } AConsole.log (Newdate.format (' Yyyy-mm-dd h:m:s '));
javascript-time Stamp