On Tue, 6 Dec 2005 12:36:55 -0800 (PST), Jean Johnson <[EMAIL PROTECTED]> wrote:

>Hello - 
>
>I have a start and end time that is written using the
>following:
>
>time.strftime("%b %d %Y  %H:%M:%S")
>
>How do I calculate the elapsed time?
>
 >>> tf1 = time.strftime("%b %d %Y  %H:%M:%S")
 >>> tf1
 'Dec 06 2005  14:07:11'
 >>> tt1 = time.strptime(tf1, "%b %d %Y  %H:%M:%S" )
 >>> tt1
 (2005, 12, 6, 14, 7, 11, 1, 340, -1)
 >>> t1 = time.mktime(tt1)
 >>> t1
 1133906831.0
 >>> tf2 = time.strftime("%b %d %Y  %H:%M:%S")
 >>> tf2
 'Dec 06 2005  14:08:34'
 >>> tt2 = time.strptime(tf2, "%b %d %Y  %H:%M:%S" )
 >>> tt2
 (2005, 12, 6, 14, 8, 34, 1, 340, -1)
 >>> t2 = time.mktime(tt2)
 >>> t2
 1133906914.0
 >>> t2-t1
 83.0
(seconds elapsed)

Perhaps time was available as a number before stftime was used? E.g., t2 can 
round trip:
 >>> time.ctime(t2)
 'Tue Dec 06 14:08:34 2005'
 >>> time.strftime("%b %d %Y  %H:%M:%S", time.localtime(t2))
 'Dec 06 2005  14:08:34'
 >>> time.strftime("%b %d %Y  %H:%M:%S", time.gmtime(t2))
 'Dec 06 2005  22:08:34'


for more info, see time module docs at

    http://www.python.org/doc/current/lib/module-time.html

and in general, learn how to find info starting at

    http://www.python.org/doc/

also, interactively,
    import time
    help(time)

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to