1环揽、js時(shí)間函數(shù)getTime() 在蘋果手機(jī)上返回NaN的問(wèn)題
在蘋果手機(jī)上時(shí)間格式使用“/” 隔開(kāi)表示略荡。
const start_time = '2019-10-21 00:00:00'
const start = (new Date(start_time.replace(/-/g, '/'))).getTime() // 得到時(shí)間戳
2、獲取當(dāng)天時(shí)間的23:59:59的時(shí)間戳
getToday () {
var myDate = new Date()
myDate.getFullYear() // 獲取完整的年份
myDate.getMonth() // 獲取當(dāng)前月份(0-11,0代表1月)
myDate.getDate() // 獲取當(dāng)前日(1-31)
const today = myDate.getFullYear() + '/' + (myDate.getMonth() + 1) + '/' + myDate.getDate() + ' ' + '23:59:59'
return new Date(today).getTime()
}
3歉胶、時(shí)間范圍比較 (時(shí)間戳的比較)
const start = (new Date(item.Data.start_time.replace(/-/g, '/'))).getTime()
const end = (new Date(item.Data.end_time.replace(/-/g, '/'))).getTime() + 24 * 60 * 60 * 1000 - 1
const today = this.getToday()
if (today < start) { // 未開(kāi)始
this.recordInfo.dateStatu = 1
} else if (today > end) { // 已結(jié)束
this.recordInfo.dateStatu = 3
} else { // 進(jìn)行中
this.recordInfo.dateStatu = 2
}