I\'m having trouble formatting a datetime.timedelta
object.
Here\'s what I\'m trying to do: I have a list of objects and one of the members of the cl
>>> str(datetime.timedelta(hours=10.56))
10:33:36
>>> td = datetime.timedelta(hours=10.505) # any timedelta object
>>> ':'.join(str(td).split(':')[:2])
10:30
Passing the timedelta
object to the str()
function calls the same formatting code used if we simply type print td
. Since you don't want the seconds, we can split the string by colons (3 parts) and put it back together with only the first 2 parts.