1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
const today = '2025-01-20' const start = '2025-01-18' const end = '2025-01-25' let statusName = '' if (start < today && today < end) { statusName = '正在进行' } else if (start > today) { statusName = '未开始' } else if (end < today) { statusName = '已结束' } console.log(statusName)
const today = new Date().getTime() const start = new Date('2025-01-18 11:50:00').getTime() const end = new Date('2025-01-25 11:50:00').getTime() let statusName = '' if (start < today && today < end) { statusName = '正在进行' } else if (start > today) { statusName = '未开始' } else if (end < today) { statusName = '已结束' } console.log(statusName)
function compareDates(date1, date2) { const d1 = new Date(date1).getTime() const d2 = new Date(date2).getTime()
if (d1 === d2) { return 0 } else if (d1 > d2) { return 1 } else { return -1 } } console.log(compareDates('2025-01-01', '2025-01-02')) console.log(compareDates('2025-01-03', '2025-01-03')) console.log(compareDates('2025-01-04', '2025-01-03'))
|