I want to calculate time difference between two times which are in 24hours format. Suppose start time is 23.00 PM and endtime is 2.00 AM. Then it should show 3 hours.
Can anyone please help me how to do this.
To compare dates, the best way is to use the date in milliseconds with the function getTime()
.
const diffInMilliseconds = endTime.getTime() - starTime.getTime() // 10800000
const diffInHours = diffInMilliseconds / 3600000 // 3 hours
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.