Date.prototype.Format = function (fmt) {
var o = {
'M+': this.getMonth() + 1,
'd+': this.getDate(),
'H+': this.getHours(),
'm+': this.getMinutes(),
's+': this.getSeconds(),
'S+': this.getMilliseconds()
};
var fmtMatch = fmt.match(/(y+)/);
if (fmtMatch) {
fmt = fmt.replace(fmtMatch[0], (this.getFullYear() + '').substring(4 - fmtMatch[0].length));
}
for (var k in o) {
fmtMatch = fmt.match('(' + k + ')');
if (fmtMatch) {
fmt = fmt.replace(fmtMatch[0], (fmtMatch[0].length == 1) ? (o[k]) : (('00' + o[k]).substring(String(o[k]).length)));
}
}
return fmt;
};
var df = new Date().Format('yyyy-MM-dd HH:mm:ss');
console.log(`df:${df}`);
网友评论