Python summing up time

后端 未结 9 1682
后悔当初
后悔当初 2020-12-06 00:55

In python how do I sum up the following time?

 0:00:00
 0:00:15
 9:30:56
9条回答
  •  遥遥无期
    2020-12-06 01:11

    lines = ["0:00:00", "0:00:15", "9:30:56"]
    total = 0
    for line in lines:
        h, m, s = map(int, line.split(":"))
        total += 3600*h + 60*m + s
    print "%02d:%02d:%02d" % (total / 3600, total / 60 % 60, total % 60)
    

提交回复
热议问题