Format timedelta to string

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

    I used the humanfriendly python library to do this, it works very well.

    import humanfriendly
    from datetime import timedelta
    delta = timedelta(seconds = 321)
    humanfriendly.format_timespan(delta)
    
    '5 minutes and 21 seconds'
    

    Available at https://pypi.org/project/humanfriendly/

提交回复
热议问题