delta time = time stop - time start
Guilherme Salgado
salgado at freeshell.org
Mon Jan 26 06:07:34 EST 2004
On Mon, 2004-01-26 at 04:08, engsol wrote:
[...]
> The routine I came up with is below, but seems a bit clunky.
> Is there a better way of doing this? I think it relies too much on integers rounding off in the proper direction, a la
> d_time_hr = d_time / 3600 below.
>
You can use mx.DateTime
(http://www.lemburg.com/files/python/mxDateTime.html).
Then, the code will look like this:
from mx import DateTime
start = DateTime.now()
# do something ...
stop = DateTime.now()
delta = (stop - start).strftime("%H:%M:%S")
hope it helps.
> Also, this will have to transition to Linux, if that makes a difference.
>
> START CODE:
>
> import string
>
> def deltatime(start, stop):
>
> t_start = (string.atoi(start[0:2]) * 3600) + (string.atoi(start[3:5]) * 60) + string.atoi(start[6:8])
> t_stop = (string.atoi(stop [0:2]) * 3600) + (string.atoi(stop [3:5]) * 60) + string.atoi(stop [6:8])
>
> if t_start < t_stop:
> d_time = t_stop - t_start
> else:
> d_time = (86400 - t_start) + t_stop
>
> d_time_hr = d_time / 3600
> d_time_min = (d_time - d_time_hr * 3600) / 60
> d_time_sec = (d_time - d_time_hr * 3600) - (d_time_min * 60)
>
> return str(d_time_hr) + 'hr ' + str(d_time_min) + 'min ' + str(d_time_sec) + 'sec'
>
> END CODE
[]'s
Salgado
--
This email has been inspected by Hans Blix, who has reported that no
weapons of mass destruction were used in its construction.
Read his report here:
<http://www.un.org/apps/news/infocusnewsiraq.asp?NewsID=414&sID=6>
More information about the Python-list
mailing list