invalid time - why ?

Peter Otten __peter__ at web.de
Tue Dec 9 11:11:12 EST 2003


fowlertrainer at anonym.hu wrote:

> Hello python-list,
>     starttime=time.time()
>     .... process ....
>     endtime=time.time()
>     dtime=endtime-starttime
>     print "Started at:",
>     time.strftime("%H:%M:%S",time.localtime(starttime)) print "Ended at:",
>     time.strftime("%H:%M:%S",time.localtime(endtime))
>     #print time.localtime(dtime)
>     print "Deltatime: ", time.strftime("%H:%M:%S",time.localtime(dtime))
> 
> My problem is in the result:
> 
>> Executing: C:\Program Files\ConTEXT\ConExec.exe "C:\Python\python.exe"
>> "C:\dev\PYTPFlood\pytpflood.py"
> 
> Parameters are: {'host': 'http://ks/', 'repeat': 1, 'threads': 1, 'port':
> 80, 'slip': 1000}
> Request:  1
> Thread count: 0
> Started at: 15:12:04
> Ended at: 15:12:05
> Deltatime:  01:00:01 ????????? <--- why ?
>> Execution finished.
> 
> What I do wrong ?
> 
> The deltatime hour section is wrong. But why ?

The extra hour comes from your timezone being Middle European Time (1 hour
ahead of GMT) whereas the Unix epoch starts on Jan 1, 1970, 00:00:00 GMT.
The displayed results of your script will vary with the timezone used when
you execute it.
To fix it, replace time.localtime() with time.gmtime() in the above.
Otherwise your approach should work as long as you are displaying time spans
that amount to less than 24 hours.

Peter





More information about the Python-list mailing list