views:

76

answers:

2
>>> from datetime import datetime
>>> t1 = datetime.now()
>>> t2 = datetime.now()
>>> delta = t2 - t1
>>> delta.seconds
7
>>> delta.microseconds
631000

Is there any way to get that as 7.631000 ? I can use time module, but I also need that t1 and t2 variables as DateTime objects. So if there is an easy way to do it with datettime, that would be great. Otherwise it'll look ugly:

t1 = datetime.now()
_t1 = time.time()
t2 = datetime.now()
diff = time.time() - _t1
+3  A: 

combined = delta.seconds + delta.microseconds/1E6

scompt.com
or combined = delta.seconds + (float(1) / delta.microseconds)
pocoa
+1  A: 

I don't know if there is a better way, but:

((1000000 * delta.seconds + delta.microseconds) / 1000000.0)

or possibly:

"%d.%06d"%(delta.seconds,delta.microseconds)
Douglas Leeder