python中2个给定时间(以毫秒为单位)之间的差异

我有两次以下格式.
我想找到以毫秒为单位的时差.
这只给出了秒精度.
如何使这项工作毫秒?
谢谢. 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
上一篇:CentOS 7.2.1511编译安装Nginx1.10.1+MySQL5.6.33+PHP5.6.26


下一篇:计算几小时和几分钟的PHP