Time Difference

Fredrik Lundh fredrik at pythonware.com
Fri Dec 17 10:40:19 EST 2004


"GMane Python" <s_david_rose at hotmail.com> wrote:

>  I was wondering if there is an existing function that would let me
> determine the difference in time.  To explain:
>
> Upon starting a program:
>
> startup = time.time()
>
> After some very long processing:
> now = time.time()
>
> print <days> <hours> <minutes> <seconds>, now - startup
>
> So, to print in a formatted way (D-H-M-S) the difference in time of startup
> and now.

now - startup gives you the difference in seconds; turning that into (days,
hours, minutes, seconds) isn't that hard (hint: lookup the divmod function
in the manual).

or you could use the datetime module:

>>> from datetime import datetime
>>> startup = datetime.today()
>>> now = datetime.today()
>>> print now - startup
0:00:06.625000

(see the library reference for details).

</F> 






More information about the Python-list mailing list