Home > Net >  Python3 Find time duration between two epoch millisecond times
Python3 Find time duration between two epoch millisecond times

Time:03-23

I have two epoch times in milliseconds, I need to find the duration between them. For instance:

1637264400000 - November 18, 2021 11:40:00 AM

1637280000000 - November 18, 2021 4:00:00 PM

In this case the time difference is 4 hours and 20 minutes. I tried to subtract the two times as in :

1637280000000 - 1637264400000 = 15600000

But then I don't know how to compute 15600000 in duration. If I used an epoch time convertor then 15600000 just converts to June 30, 1970 6:20:00 AM .

So, how do I compute the duration in days/hours/minutes?

CodePudding user response:

For all practical purposes you probably want to work with a timedelta instance. Using only the milliseconds delta:

>>> from datetime import timedelta
>>> print(timedelta(milliseconds=15600000))
4:20:00
  • Related