getDate() {
const date = new Date()
const year = date.getFullYear()
const month = date.getMonth() + 1
// 上月结束时间
const end_date = new Date(year, month - 1, 0)
const end_day = end_date.getDate()
this.endLastMonth = `${year}-${month - 1}-${end_day}`
// 今天
const day = () => {
let Day = date.getDate()
if (Day < 10) {
Day = '0' + Day
return Day
} else {
return Day
}
}
// 昨天
const lastday = () => {
let Day = date.getDate()
if (Day == 1) {
Day = end_day
return `${year}-${month - 1}-${Day}`
} else if (Day < 10) {
Day = Day - 1
Day = '0' + Day
return `${year}-${month}-${Day}`
} else {
return `${year}-${month}-${Day - 1}`
}
}
// 近七天
const nearlySevenDays = () => {
let Day = date.getDate()
if (Day == 6) {
return `${year}-${month - 1}-${end_day}`
} else if (Day < 6) {
Day = end_day - (6 - Day)
return `${year}-${month - 1}-${Day}`
} else if (Day < 10) {
Day = Day - 6
Day = '0' + Day
return `${year}-${month}-${Day}`
} else {
Day = Day - 6
return `${year}-${month}-${Day}`
}
}
// 今日
this.nowDate = `${year}-${month}-${day()}`
// 昨天
this.lastDate = lastday()
// 当月
this.nowMonth = `${year}-${month}-01`
// 上月
this.lastMonth = `${year}-${month - 1}-01`
// 近七天
this.nearlySevenDays = nearlySevenDays()
// console.log('今日', this.nowDate)
// console.log('昨天', this.lastDate)
// console.log('当月', this.nowMonth)
// console.log('上月', this.lastMonth)
// console.log('近七天', this.nearlySevenDays)
// console.log('end_date', end_date, end_day, this.endLastMonth)
},
获取时间
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 本文参考原文-http://bjbsair.com/2020-03-25/tech-info/6342.html ...
- ECMAScript - 学习笔记 🎬 🧩nvm node.js 包管理工具 nvm github[https:/...