Format timedelta to string

后端 未结 28 2062
春和景丽
春和景丽 2020-11-22 03:57

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

28条回答
  •  独厮守ぢ
    2020-11-22 04:03

    If you already have a timedelta obj then just convert that obj into string. Remove the last 3 characters of the string and print. This will truncate the seconds part and print the rest of it in the format Hours:Minutes.

    t = str(timedeltaobj) 
    
    print t[:-3]
    

提交回复
热议问题