Java code // convert the date type to string & lt ;! --/*** Extend Date to String * month (M), Day (d), 12 hours (h), and 24 hours (H) in the specified format), minute (m), second (s), Week (E), quarter (q) can use 1-2 placeholders * Year (y) can use 1-4 placeholders... synt
Java code
// Convert the date type to string
Date. prototype. pattern = function (fmt ){
Var o = {
"M +": this. getMonth () + 1, // month
"D +": this. getDate (), // day
"H +": this. getHours () % 12 = 0? 12: this. getHours () % 12, // hour
"H +": this. getHours (), // hour
"M +": this. getMinutes (), // minute
"S +": this. getSeconds (), // second
"Q +": Math. floor (this. getMonth () + 3)/3), // quarter
"S": this. getMilliseconds () // millisecond
};
Var week = {
"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 (var k in o ){
If (new RegExp ("(" + k + ")"). test (fmt )){
Fmt = fmt. replace (RegExp. $1, (RegExp. $1. length = 1 )? (O [k]): ("00" + o [k]). substr ("" + o [k]). length )));
}
}
Return fmt;
}
Author "sljackson"