I know that this is an old answered question, but I use datetime.utcfromtimestamp()
for this. It takes the number of seconds and returns a datetime
that can be formatted like any other datetime
.
duration = datetime.utcfromtimestamp(end - begin)
print duration.strftime('%H:%M')
As long as you stay in the legal ranges for the time parts this should work, i.e. it doesn't return 1234:35 as hours are <= 23.