Javascript date and Time conversion method. If you need a friend, please refer to the Microsoft Json serialization library in use. Then date will be
The Code is as follows:
/Date (1224043200000 )/
The effective method is
Mydate. replace (// Date \((.*?) \) \ // Gi, "new Date ($1 )");
If you want to convert the format, you 'd better write an extension method:
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;
}
After conversion:
Var nDate = mydate. replace (// Date \((.*?) \) \ // Gi, "new Date ($1 )");
NDate. pattern ("yyyy-MM-dd hh: mm ");