/** * @author ocq* * Extension to date, convert date to string in specified format (m), Day (d), 12 hours (h), 24 hours (h), minutes (m), seconds (s), Week (E), quarter (q) can use 1-2 placeholders * years (y) You can use 1-4 placeholders, milliseconds (S) with only 1 placeholders (1-3 digits) * Eg: * (new Date ()). DateFormat ("Yyyy-mm-dd hh:mm:ss. S ") ==> 2006-07-02 08:09:04.423 * (New Date ()). DateFormat (" Yyyy-mm-dd E HH:mm:ss ") ==> 2009-03-10 II 20:09:04 * (NEW Date ()). DateFormat ("Yyyy-mm-dd EE hh:mm:ss") ==> 2009-03-10 Tuesday 08:09:04 * (New Date ()). DateFormat ("Yyyy-mm-dd EEE hh:m M:ss ") ==> 2009-03-10 Tuesday 08:09:04 * (New Date ()). DateFormat (" yyyy-m-d h:m:s.s ") ==> 2006-7-2 8:9:4.18*/Date.prototype.dateFormat=function(FMT) {varo = { "m+": This. GetMonth () +1,//Month"D+": This. GetDate (),//Day"H +": This. getHours ()%12 = = 0? 13 [ This. GetHours ()%12,//hours"H +": This. GetHours (),//hours"m+": This. getminutes (),//points"S+": This. getseconds (),//seconds"q+": Math.floor (( This. GetMonth () +3)/3),//Quarterly"S ": This. Getmilliseconds ()//milliseconds}; varWeek = { "0": "\u65e5", "1": "\u4e00", "2": "\u4e8c", "3": "\u4e09", "4": "\u56db", "5": "\u4e94", "6": "\U516D" }; if(/(y+)/. Test (FMT)) {FMT=fmt.replace (Regexp.$1, ( This. getFullYear () + ""). substr (4-regexp.$1. length)); } if(/(e+)/. Test (FMT)) {FMT=fmt.replace (regexp.$1, (regexp.$1.length>1)? (regexp.$1.length>2?) "\u661f\u671f": "\u5468"): "") +week[ This. GetDay () + ""]); } for(varKincho) { if(NewRegExp ("(" + K + ")"). Test (FMT)) {FMT= Fmt.replace (regexp.$1, (regexp.$1.length==1)? (O[k]): (("XX" + o[k]). substr ("" +o[k])); } } returnFMT;}
JS Date Format function