/**
* 格式化时间
* @param {Datetime} source 时间对象
* @param {String} format 格式
* @return {String} 格式化过后的时间
*/
function formatDate (source, format) {
source = new Date(source);
const o = {
// 'Y+': source.getFullYear(),
'M+': source.getMonth() + 1, // 月份
'd+': source.getDate(), // 日
'H+': source.getHours(), // 小时
'm+': source.getMinutes(), // 分
's+': source.getSeconds(), // 秒
'q+': Math.floor((source.getMonth() + 3) / 3), // 季度
'f+': source.getMilliseconds() // 毫秒
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (source.getFullYear() + '').substr(4 - RegExp.$1.length))
}
for (let 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
}
formatDate(1571885235219,"yyyy年MM月dd日 HH:mm:ss");