Format timedelta to string

后端 未结 28 1697
春和景丽
春和景丽 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:26

    You can just convert the timedelta to a string with str(). Here's an example:

    import datetime
    start = datetime.datetime(2009,2,10,14,00)
    end   = datetime.datetime(2009,2,10,16,00)
    delta = end-start
    print(str(delta))
    # prints 2:00:00
    

提交回复
热议问题