1、獲取某月第一天和最後一天日期
function getDateByMonth (timeStamp) {
let inDate = new Date(timeStamp)
let year = inDate.getFullYear()
let month = inDate.getMonth()
let startTime = new Date(year, month, 1).getTime()
let endTime = new Date(year, month + 1, 0).getTime()
return {
startTime: startTime,
endTime: endTime
}
}
2、獲取某月第一天和最後一天時間戳
/** 根據時間戳 獲取其月開始時間戳和結束時間戳 */
function getTimeStamp (timeStamp) {
let inDate = new Date(timeStamp)
let year = inDate.getFullYear()
let month = inDate.getMonth()
let startTime = new Date(year, month, 1).getTime()
let endTime = new Date(year, month + 1, 1).getTime() - 1
return {
startTime: startTime,
endTime: endTime
}
}