this.dateB = '2020-5-20'
let week = new Date(this.dateB)
week = week.setDate(week.getDate() - 1)
// week = new Date(week).toLocaleString().split(' ')[0]
week = 2020/5/19
格式化日期
const date = Date.prototype
date.format = function (format) {
let o = {
'M+': this.getMonth() + 1,
'd+': this.getDate(),
'h+': this.getHours(),
'm+': this.getMinutes(),
's+': this.getSeconds(),
'q+': Math.floor((this.getMonth() + 3) / 3),
'S': this.getMilliseconds()
}
if (/(y+)/.test(format)) {
format = format.replace(
RegExp.1.length)
)
}
for (let k in o) {
if (new RegExp('(' + k + ')').test(format)) {
format = format.replace(
RegExp.1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
)
}
}
return format
}
网友评论