js 获取某月第一天和最后一天
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
}
}