1 //An extension to date that converts date to a string of the specified format2 //the Month (m), Day (d), hour (h), Minute (m), second (s), quarter (q) can be used with 1-2 placeholders,3 //year (Y) can use 1-4 placeholders, milliseconds (S) with only 1 placeholders (1-3 digits)4 //Example:5 //(New Date ()). Format ("Yyyy-mm-dd HH:mm:ss. S ") ==> 2006-07-02 08:09:04.4236 //(New Date ()). Format ("yyyy-m-d h:m:s.s") ==> 2006-7-2 8:9:4.187Date.prototype.Format =function(FMT) {//Author:meizz8 varo = {9"m+": This. GetMonth () + 1,//MonthTen"D+": This. GetDate (),//Day One"H +": This. GetHours (),//hours A"m+": This. getminutes (),//points -"S+": This. getseconds (),//seconds -"q+": Math.floor (( This. GetMonth () + 3)/3),//Quarterly the"S": This. Getmilliseconds ()//milliseconds - }; - if(/(y+)/. Test (FMT)) -FMT = Fmt.replace (regexp.$1, ( This. getFullYear () + ""). substr (4-regexp.$1. length)); + for(varKincho) - if(NewRegExp ("(" + K + ")"). Test (FMT)) +FMT = Fmt.replace (regexp.$1, (regexp.$1.length = = 1)? (O[k]): (("XX" + o[k]). substr ("" +O[k] )); A returnFMT; at}
JS Date Object Extension