我有两次以下格式.
我想找到以毫秒为单位的时差.
这只给出了秒精度.
如何使这项工作毫秒?
谢谢. python新手.
import time
t1 = "2013-09-13 15:43:35,893"
t2 = "2013-09-13 15:43:45,147"
TIME_FORMAT2 = "%Y-%m-%d %H:%M:%S,%f"
t11 = time.mktime(time.strptime(t1, TIME_FORMAT2))
t12 = time.mktime(time.strptime(t2, TIME_FORMAT2))
print t11-t12
解决方法:
>>> from datetime import datetime
>>> datetime.strptime(t1, TIME_FORMAT2) - datetime.strptime(t2, TIME_FORMAT2)
datetime.timedelta(-1, 86390, 746000)
>>> _.total_seconds()
-9.254