I am confused why the difference between these two dates has a default of 8 hours? I am expecting a result something like 00:12:32 at least in my case from the time I posted this. Right now, in the result, the hour has a default of 8.
JavaScript
x
11
11
1
const date1 = dayjs(Date.now())
2
const date2 = dayjs(1674235010388)
3
4
// Check date date1
5
console.log('date1 =', dayjs(date1).format('hh:mm:ss'))
6
7
// Check date2 date
8
console.log('date2 =', dayjs(date2).format('hh:mm:ss'))
9
10
const result = date1.diff(date2)
11
console.log(dayjs(result).format('hh:mm:ss'))
JavaScript
1
1
1
<script src="https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js"></script>
Advertisement
Answer
I cannot tell you but it is another reason for not using these frameworks when plain JS is more predictible
JavaScript
1
9
1
const ms2hhmmss = ms => new Date(ms).toISOString().slice(11,19); // grab the time from YYYY-MM-DDTHH:MM:SS.milZ
2
3
const date1 = new Date()
4
const date2 = new Date(1674235010388)
5
console.log(date1)
6
console.log(date2)
7
8
const diff = Math.abs(date1 - date2)
9
console.log(ms2hhmmss(diff))