Writing elapsed time as a string
M.-A. Lemburg
mal at egenix.com
Thu May 8 12:08:28 EDT 2008
On 2008-05-08 14:31, Gabriel Genellina wrote:
> En Fri, 02 May 2008 16:13:41 -0300, Simon Pickles <sipickles at googlemail.com> escribió:
>
>> I'm sorry if this has been asked a thousand (million) times.
>>
>> Is there a nifty pythonesque way to produce a string representing an
>> elapsed time period, in terms of years, months, days, hours, mins, seconds?
>>
>> I am storing times in a MySQL db, and would love to be able to write the
>> time elapsed between accesses of certain data. These are in seconds
>> since the epoch, as produced by time.time()
Using mxDateTime that's pretty easy (using number of days):
>>> from mx.DateTime import *
>>> delta = now() - Date(2000,1,1)
>>> print delta
3050:18:01:25.91
or, if you'd rather like to see things broken down as relative
date/time diff (this is a calendar based diff):
>>> print RelativeDateTimeDiff(now(), Date(2000,1,1))
(+0008)-(+04)-(+07) (+18):(+04):(+41)
i.e. 8 years, 4 months, 7 days, etc.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, May 08 2008)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the Python-list
mailing list