Gshrq= {
/**
* 时间格式化,date为空时取当前时间
* format格式,
* date日期可以为空
*/
dateFormat: function (format, date) {
let result;
if (!date) {
date = new Date();
}
const option = {
"y+": date.getFullYear().toString(), // 年
"M+": (date.getMonth() + 1).toString(), // 月
"d+": date.getDate().toString(), // 日
"h+": date.getHours().toString(), // 时
"m+": date.getMinutes().toString(), // 分
"s+": date.getSeconds().toString() // 秒
};
for (let i in option) {
result = new RegExp("(" + i + ")").exec(format);
if (result) {
format = format.replace(result[1], (result[1].length == 1) ? (option[i]) : (option[i].padStart(result[1].length, "0")))
}
}
return format;
},
};
使用
let now=Gshrq.dateFormat("yyyy-MM-dd mm:ss"); _this.savaContentLabel="最后保存时间:"+now;