Set the time format to Date. prototype. formatfunction (format) {varo {M +: this. getMonth () + 1, monthd +: this. getDate (), dayh +: this. getHours (), hourm +: this. getMinutes (), minutes +: this. getSeconds (), secondq +:
// Set Date in time format. prototype. format = function (format) {var o = {"M +": this. getMonth () + 1, // month "d +": this. getDate (), // day "h +": this. getHours (), // hour "m +": this. getMinutes (), // minute "s +": this. getSeconds (), // second "q + ":
// Set the time format
Date. prototype. format = function (format ){
Var o = {
"M +": this. getMonth () + 1, // month
"D +": this. getDate (), // day
"H +": this. getHours (), // hour
"M +": this. getMinutes (), // minute
"S +": this. getSeconds (), // second
"Q +": Math. floor (this. getMonth () + 3)/3), // quarter
"S": this. getMilliseconds () // millisecond
};
If (/(y +)/. test (format )){
Format = format. replace (RegExp. $1,
(This. getFullYear () + ""). substr (4-RegExp. $1. length ));
}
For (var k in o ){
If (new RegExp ("(" + k + ")"). test (format ))
Format = format. replace (RegExp. $1,
RegExp. $1. length = 1? O [k]: ("00" + o [k]). substr ("" + o [k]). length ));
}
Return format;
}
// Usage
Var d = new Date ();
D. format ("h ");
// Determine the time
Function convertdate (strdate ){
Strdate = strdate. replace (/-/ig ,'/');
Var d = new Date (strdate );
Var now = new Date ();
Var result;
If (d. getYear () = now. getYear () & d. getMonth () = now. getMonth ()){
Var xday = now. getDate ()-d. getDate ();
Switch (xday ){
Case 0:
Result = "today" + d. format ("hh") + ":" + d. format ("mm") + ":" + d. format ("ss ");
Break;
Case 1:
Result = "yesterday" + d. format ("hh") + ":" + d. format ("mm") + ":" + d. format ("ss ");
Break;
Case 2:
Result = "the day before yesterday" + d. format ("hh") + ":" + d. format ("mm") + ":" + d. format ("ss ");
Break;
Default:
Result = d. format ("yyyy-MM-dd hh: mm ");
Break;
}
} Else {
Result = d. format ("yyyy-MM-dd hh: mm ");
}
Return result;
}