You are not logged in.
Is there a function to convert the integer 80 to the string '01:20'? Thanks.
Last edited by Boris Bolgradov (2009-08-09 06:08:41)
Offline
Never mind... I found what I need
Offline
Care to share for us less python gifted individuals?
- J
Offline
Care to share for us less python gifted individuals?
- J
What you want is in the time module.
time.strftime("%Y-%m-%d %H.%M.%S")
Prints '2009-08-09 10.31.33' for me.
Rest of the formatting codes: http://docs.python.org/library/time.html
Also look at the datetime module for other representations.
Cthulhu For President!
Offline
@buttons: I think you misread my question.
@jbusch: Sure, here's the code:
def humanize_time(secs):
mins, secs = divmod(secs, 60)
hours, mins = divmod(mins, 60)
return '%02d:%02d:%02d' % (hours, mins, secs)
>>> humanize_time(90)
'00:01:30'
>>> humanize_time(6513)
'01:48:33'
Offline
In [1]: import datetime
In [2]: str(datetime.timedelta(seconds=6513))
Out[2]: '1:48:33'
Regards,
raf
Offline
Hehe, very nice! Thanks!
Offline
Very nice. Thank you.
Offline