一天 = 24 * 60 * 60 * 1000
所以
时间戳除以一天向下取整如果两者相等 即为同一天
- const timestamp1 = Math.floor(1624190400000/(24*60*60*1000)); // 2021-07-19 00:00:00 UTC
- const timestamp2 = Math.floor(1624276800000/(24*60*60*1000)); // 2021-07-19 23:59:59 UTC
- console.log(timestamp1, timestamp2)
-
- const isSameDay = (a, b) => {
- return Math.floor(a/(24*60*60*1000)) === Math.floor(b/(24*60*60*1000))
- }