Copy Code code as follows:
/**
* The format of the time object;
*/
Date.prototype.format = function (format) {
/*
* eg:format= "Yyyy-mm-dd hh:mm:ss";
*/
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]
: ("+ o[k]"). substr (("" "+ o[k]). length);
}
}
return format;
}
Copy Code code as follows:
var now = new Date (). Format ("Yyyy-mm-dd hh:mm:ss");
Copy Code code as follows:
New Date (). Format ("Yy-mm-dd hh:mm");