Skip to content
Advertisement

Javascript return number of days,hours,minutes,seconds between two dates

Does anyone can link me to some tutorial where I can find out how to return days , hours , minutes, seconds in javascript between 2 unix datetimes?

I have:

JavaScript

I would like to return (live) how many days,hours,minutes,seconds left from the date_now to the date_future.

Advertisement

Answer

Just figure out the difference in seconds (don’t forget JS timestamps are actually measured in milliseconds) and decompose that value:

JavaScript

EDIT code adjusted because I just realised that the original code returned the total number of hours, etc, not the number of hours left after counting whole days.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement