First, Pure JS format time
Previously recorded some, work found in the more commonly used, just record it.
Because of the very foundation, it is directly posted out, do not do analysis.
Transform the prototype of date
Date.prototype.format =function(format) {varn \ { "m+": This. GetMonth () +1,//Month"D+": This. GetDate (),// Day"H +": This. GetHours (),//Hour"m+": This. getminutes (),//minute"S+": This. getseconds (),//Second"q+": Math.floor (( This. GetMonth () +3)/3),//quarter "S": This. Getmilliseconds ()//Millisecond } if(/(y+)/. Test (format)) {Format= Format.replace (Regexp.$1, ( This. getFullYear () + ""). substr (4-regexp.$1. length)); } for(varKincho) {if(NewRegExp ("(" + K + ")"). Test (format)) {format= Format.replace (regexp.$1, Regexp.$1.length==1 o[k]: ("XX" + o[k]). substr ("" +O[k]) (length)); } } returnformat;}
Let's see how to use it.
//How to usevarnow =NewDate ();varNowstr = Now.format ("Yyyy-mm-dd hh:mm:ss"); //Use Method 2:varTestDate =NewDate ();varTeststr = Testdate.format ("yyyy mm month DD day hh hours mm min ss sec"); alert (TESTSTR); //Example:Console.log (NewDate (). Format ("yyyy mm month DD Day")); Console.log (NewDate (). Format ("mm/dd/yyyy")); Console.log (NewDate (). Format ("YyyyMMdd")); Console.log (NewDate (). Format ("Yyyy-mm-dd hh:mm:ss"));
Look at the results of the implementation.
Still good use of it, put this short JS code into the common JS file, and then directly use it, you do not have to transform the ha.
JS/JQ Basics (daily housekeeping Records)-Pure JS format time