invalid time - why ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fowlertrainer@anonym.hu

    invalid time - why ?

    Hello python-list,
    starttime=time. time()
    .... process ....
    endtime=time.ti me()
    dtime=endtime-starttime
    print "Started at:", time.strftime(" %H:%M:%S",time. localtime(start time))
    print "Ended at:", time.strftime(" %H:%M:%S",time. localtime(endti me))
    #print time.localtime( dtime)
    print "Deltatime: ", time.strftime(" %H:%M:%S",time. localtime(dtime ))

    My problem is in the result:
    [color=blue]
    > Executing: C:\Program Files\ConTEXT\C onExec.exe "C:\Python\pyth on.exe" "C:\dev\PYTPFlo od\pytpflood.py "[/color]

    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 ?[color=blue]
    > Execution finished.[/color]

    What I do wrong ?

    The deltatime hour section is wrong. But why ?


    Thanx.

    --
    Best regards,
    fowlertrainer mailto:fowlertr ainer@anonym.hu


  • Thomas Guettler

    #2
    Re: invalid time - why ?

    Am Tue, 09 Dec 2003 15:14:51 +0100 schrieb fowlertraine:
    [color=blue]
    > Hello python-list,
    > starttime=time. time()
    > .... process ....
    > endtime=time.ti me()
    > dtime=endtime-starttime
    > print "Started at:", time.strftime(" %H:%M:%S",time. localtime(start time))
    > print "Ended at:", time.strftime(" %H:%M:%S",time. localtime(endti me))
    > #print time.localtime( dtime)
    > print "Deltatime: ", time.strftime(" %H:%M:%S",time. localtime(dtime ))[/color]

    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


    Comment

    • Peter Otten

      #3
      Re: invalid time - why ?

      fowlertrainer@a nonym.hu wrote:
      [color=blue]
      > Hello python-list,
      > starttime=time. time()
      > .... process ....
      > endtime=time.ti me()
      > dtime=endtime-starttime
      > print "Started at:",
      > time.strftime(" %H:%M:%S",time. localtime(start time)) print "Ended at:",
      > time.strftime(" %H:%M:%S",time. localtime(endti me))
      > #print time.localtime( dtime)
      > print "Deltatime: ", time.strftime(" %H:%M:%S",time. localtime(dtime ))
      >
      > My problem is in the result:
      >[color=green]
      >> Executing: C:\Program Files\ConTEXT\C onExec.exe "C:\Python\pyth on.exe"
      >> "C:\dev\PYTPFlo od\pytpflood.py "[/color]
      >
      > 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 ?[color=green]
      >> Execution finished.[/color]
      >
      > What I do wrong ?
      >
      > The deltatime hour section is wrong. But why ?[/color]

      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

      Comment

      Working...