Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python summing up time

Tags:

In python how do I sum up the following time?

 0:00:00  0:00:15  9:30:56 
like image 794
Hulk Avatar asked May 06 '10 12:05

Hulk


People also ask

How do you add minutes in Python?

Use the timedelta() class from the datetime module to add minutes to datetime, e.g. result = dt + timedelta(minutes=10) .


1 Answers

It depends on the form you have these times in, for example if you already have them as datetime.timedeltas, then you could just sum them up:

>>> s = datetime.timedelta(seconds=0) + datetime.timedelta(seconds=15) + datetime.timedelta(hours=9, minutes=30, seconds=56) >>> str(s) '9:31:11' 
like image 68
SilentGhost Avatar answered Oct 04 '22 12:10

SilentGhost