// 日期格式化函数,用法:new Date().Format("yyyy-MM-dd hh:mm:ss.fff")
Date.prototype.Format = function (exp) {
var t = {
"y+": `${this.getFullYear()}`, // 年
"M+": `${this.getMonth() + 1}`, // 月
"d+": `${this.getDate()}`, // 日
"h+": `${this.getHours()}`, // 时
"m+": `${this.getMinutes()}`, // 分
"s+": `${this.getSeconds()}`, // 秒
"f+": `${this.getMilliseconds()}` // 毫秒
};
for (let k in t) {
if (new RegExp(`(${k})`).test(exp)) {
if (k == "y+") {
exp = exp.replace(RegExp.$1, t[k].substr(0 - RegExp.$1.length));
} else if (k == "f+") {
exp = exp.replace(RegExp.$1, t[k].substr(0, RegExp.$1.length));
} else {
exp = exp.replace(RegExp.$1, RegExp.$1.length == 1 ? t[k] : ("00" + t[k]).substr(t[k].length));
}
}
}
return exp;
}