JavaScript Formatting of time date
For the extension of date, the date is converted to the specified format of string//months (m), days (d), hours (h), minutes (m), seconds (s), quarter (q) can be used with 1-2 placeholders,//year (Y) can use 1-4 placeholders, milliseconds (s) only 1 placeholders (is 1-3 Number of bits)//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) {var o = {"m+": This.getmonth () +1, //month "d+": this.getdate (),// Day "H +": this.gethours (), //Hour "m+": this.getminutes (), // Sub "s+": This.getseconds (), //sec "q+": Math.floor ((This.getmonth () +3)/3),//quarterly "s" : This.getmilliseconds () ///msec};if (/(y+)/.test (FMT)) Fmt=fmt.replace (Regexp.$1, (this.getfullyear () + ""). substr ( 4-regexp.$1.length)); (var k in O) if (New RegExp ("(" + K + ")"). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length ==1)? (O[k]): (("XX" + o[k]). substr (("" + o[k])); return FMT;};
JavaScript Formats the time date