美文网首页
2020-05-19日期加1减1

2020-05-19日期加1减1

作者: ClarkM | 来源:发表于2020-05-19 11:40 被阅读0次
      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, (this.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
}

相关文章

网友评论

      本文标题:2020-05-19日期加1减1

      本文链接:https://www.haomeiwen.com/subject/gmnvohtx.html