Date.prototype.format =function(format) {varo = { "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;} //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:AlertNewDate (). Format ("yyyy mm month DD Day")); Alert (NewDate (). Format ("mm/dd/yyyy")); Alert (NewDate (). Format ("YyyyMMdd")); Alert (NewDate (). Format ("Yyyy-mm-dd hh:mm:ss"));
JS Date Format function