python - Convert datetime.timedelta Object to HH:MM -


this question has answer here:

my database table has column datatype datetime, when queried returns hh:mm:ss. however, using python returns (datetime.timedelta(0, 57360),).

this time difference in seconds. how convert returned object string in format hh:mm?

that's how can print time:

import datetime  delta = datetime.timedelta(0, 57360) sec = delta.seconds hours = sec // 3600 minutes = (sec // 60) - (hours * 60) print(hours, ':', minutes) 

you can print time seconds by

print(str(delta)) 

Comments