How to get total hours and minutes for timedelta in Python

后端 未结 3 577
孤街浪徒
孤街浪徒 2020-12-10 01:07

How do I return or turn a timedelta, which is bigger than 24 hours, into an object containing the total hours and minutes (for example, 26:30) instead of \"1 day, 2:30\"?

3条回答
  •  自闭症患者
    2020-12-10 01:42

    You can use total_seconds() to compute the number of seconds. This can then be turned into minutes or hours:

    >>> datetime.timedelta(days=3).total_seconds()
    259200.0
    

提交回复
热议问题