const fmt = (fmt) => {
const weekday = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
const o = {
'd+': new Date().getDate(),
'h+': new Date().getHours(),
'm+': new Date().getMinutes(),
'M+': new Date().getMonth() + 1,
's+': new Date().getSeconds(),
'#': weekday[new Date().getDay()]
}
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, ('' +new Date().getFullYear()).substring(4 - RegExp.$1.length))
}
for (let k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(RegExp.$1,
RegExp.$1.length === 1?
o[k] :
('00' + o[k]).substring(('' + o[k]).length)
)
}
}
return fmt
}
console.log(fmt('yyyy.MM.dd hh:mm:ss #'))