4

I have received three different unixtimes

lastSeen = 1416248381 
firstSeen = 1416248157

and the last one is lastSeen - firstSeen:

duration = 224

Now, I can convert lastSeen and firstSeen into a datetime no problem. But I am having trouble with the duration.

I am unsure how to convert the duration into something like minutes/seconds. Does anyone have any idea if this can be done?

ApathyBear
  • 9,057
  • 14
  • 56
  • 90

1 Answers1

10

You need to convert your seconds to Hours&Minutes and you can do it using datetime

import datetime

lastSeen = 1416248381 
firstSeen = 1416248157
duration = lastSeen - firstSeen

str(datetime.timedelta(seconds=duration))

The ouput will be: '0:03:44'

Without the str() function you'll have: datetime.timedelta(0, 224)


Using time

import time

time.strftime("%H:%M:%S", time.gmtime(duration))

The ouput will be: '0:03:44'

AlvaroAV
  • 10,335
  • 12
  • 60
  • 91