Languages

JavaScript - get hours difference between two date objects

0 points
Asked by:
Dragontry
731

I've got two Date objects and I want to calculate the difference between them in hours.

How can I do that?

1 answer
0 points
Answered by:
Admin Dirask Community
4380

Quick solution:

Practical example

Using Math.abs() you can get the absolute difference between two dates in milliseconds. Then you need to divide the difference by number of milliseconds in 1 hour (1000 * 60 * 60). 

 

References

  1. Math.abs() - JavaScript | MDN
0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join