//An extension to date that converts date to a string of the specified format//the Month (m), Day (d), hour (h), Minute (m), second (s), quarter (q) can be used with 1-2 placeholders,//year (Y) can use 1-4 placeholders, milliseconds (S) with only 1 placeholders (1-3 digits)//Example://(New Date ()). Format ("Yyyy-mm-dd hh:mm:ss. S ") ==> 2006-07-02 08:09:04.423//(New Date ()). Format ("yyyy-m-d h:m:s.s") ==> 2006-7-2 8:9:4.18Date.prototype.Format =function (FMT) {varn \ { "m+": This. GetMonth () +1,//Month "d+": This. GetDate (),//Day "H +": This. GetHours (),//hours--------********* only supports 24-hour ************** "m+": This. getminutes (),//points "s+": This. getseconds (),//seconds "q+": Math.floor (( This. GetMonth () +3) /3),//Quarterly "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])); returnFMT;};//Adds the specified number of milliseconds to the value of this instanceDate.prototype.addMilliseconds =function (value) {varMillisecond = This. getmilliseconds (); This. setmilliseconds (Millisecond +value); return This;};//Adds the specified number of seconds to the value of this instanceDate.prototype.addSeconds =function (value) {varSecond = This. getseconds (); This. setseconds (Second +value); return This;};//Adds the specified number of minutes to the value of this instanceDate.prototype.addMinutes =function (value) {varminute = This. AddMinutes (); This. setminutes (Minute +value); return This;};//Adds the specified number of hours to the value of this instanceDate.prototype.addHours =function (value) {varhour = This. GetHours (); This. sethours (Hour +value); return This;};//Adds the specified number of days to the value of this instanceDate.prototype.addDays =function (value) {varDate = This. GetDate (); This. setDate (Date +value); return This;};//Adds the specified number of weeks to the value of this instanceDate.prototype.addWeeks =function (value) {return This. AddDays (Value *7);};//Adds the specified number of months to the value of this instanceDate.prototype.addMonths =function (value) {varmonth = This. GetMonth (); This. Setmonth (Month +value); return This;};//Adds the specified number of years to the value of this instanceDate.prototype.addYears =function (value) {varYear = This. getFullYear (); This. setFullYear (Year +value); return This;};
"JavaScript extended format\adddays for dates"