[Tutor] formatting datetime.timedelta to "HH:MM:SS"

Jignesh Sutar jsutar at gmail.com
Wed Dec 11 11:55:37 CET 2013


Hi,

I've googled around extensively to try figure this out assuming it should
be straight forward (and it probably is) but I'm clearly missing something.

I'm trying to get the total run time of the program but have the final time
being displayed in a particular format. I.e. without the seconds in
milliseconds decimal points and just to customize it a bit more.

import time
from datetime import datetime
startTime = datetime.now()
time.sleep(5.1564651443644)
endTime = datetime.now()
exe_time = endTime-startTime

print type(startTime)
print type(endTime)
print type(exe_time)
print "startTime: ", startTime
print "endTime:", endTime
print "exe_time: ", exe_time #how to format this to "D Days, HH: MM: SS" ?
#exe_time:  0:00:05.156000
#desired 0 Days, 0h: 00:m: 05s


Thanks in advance,
Jignesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131211/a795ec39/attachment.html>


More information about the Tutor mailing list