How to get the sum of timedelta in Python?

前端 未结 6 1952
时光说笑
时光说笑 2020-12-06 09:47

Python: How to get the sum of timedelta?

Eg. I just got a lot of timedelta object, and now I want the sum. That\'s it!

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 09:56

    If you have a list of timedelta objects, you could try:

    datetime.timedelta(seconds=sum(td.total_seconds() for td in list_of_deltas))

提交回复
热议问题