const date = new Date()
const y = date.getFullYear()
const m = date.getMonth()
let fristDay = new Date(y, m, 1)
let lastDay = new Date(y, m+1,0)
// fristDay = formatDateByJSON(fristDay.getTime())
let a = fristDay.getTime()
let b = lastDay.getTime()
if (!a) a = new Date().getTime()
else a = new Date(a).getTime()
const date1 = new Date(a + 8 * 3600 * 1000)
fristDay = date1.toJSON().substr(0, 19).replace('T', ' ').split(' ')[0]
if (!b) b = new Date().getTime()
else b = new Date(b).getTime()
const date2 = new Date(b + 8 * 3600 * 1000)
lastDay = date2.toJSON().substr(0, 19).replace('T', ' ').split(' ')[0]
console.log(fristDay)
console.log(lastDay)
获取当前月的第一天和最后一天
最新推荐文章于 2023-11-30 16:41:09 发布