Time Difference

Frans Englich frans.englich at telia.com
Fri Dec 17 10:57:59 EST 2004


On Friday 17 December 2004 15:40, Fredrik Lundh wrote:
> "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).

I've been struggling with that too. Here's some more documentation:

http://pleac.sourceforge.net/pleac_python/datesandtimes.html

I have a followup question on this, slightly off-topic:

What is the best/simplest method to transfer a time to W3C XML Schema's type 
duration[1]? Is there any helper function for that?


Cheers,

		Frans



1.
http://www.w3.org/TR/xmlschema-2/#duration



More information about the Python-list mailing list