How to get milliseconds when substructing datetime objects?
Dmitri O.Kondratiev
dokondr at gmail.com
Wed Dec 12 09:40:24 EST 2007
Please help to find simple solutiion for measuring times of operations with
millisecond precision.
For this I am trying to use datetime() objects:
import time
import datetime
def dreamTime(secs):
t1 = datetime.datetime.now()
time.sleep(secs)
t2 = datetime.datetime.now()
dt = t2 - t1
print "Start time: "+str(t1)
print "Stop time: "+str(t2)
print "Dream time sec: "+str(dt)
"""
# The following code results in errors like:
# AttributeError: 'datetime.timedelta' object has no attribute 'second'
"""
dts = dt.second
dtmicro = dt.microsecond
dtmilli = dts * 1000 + dtmicro / float(1000)
dts2 = dtmilli / float(1000)
print "Dream Millies: "+str(dtmilli)
print "Dream Seconds, again: "+str(dts2)
-----------------
Thanks!
--
Dmitri O. Kondratiev
dokondr at gmail.com
http://www.geocities.com/dkondr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071212/0277a28a/attachment.html>
More information about the Python-list
mailing list