invalid time - why ?

F

fowlertrainer

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 ?


Thanx.
 
T

Thomas Guettler

Am Tue, 09 Dec 2003 15:14:51 +0100 schrieb fowlertraine:
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))

Python like most operating system use seconds since 1970 for storing the time.

If you do "endtime-startime" your result will surely by in the year 1970.

You could do:
print "Deltatime %s hours" % float(dtime)/(60*60)

thomas
 
P

Peter Otten

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:


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 ?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,475
Latest member
ShannonGro

Latest Threads

Top