python time(milli seconds)计算

时间:2009-12-15 05:46:32

标签: python time

如何根据以下代码计算毫秒数。

a = datetime.datetime.now()
b = datetime.datetime.now()
c = b - a

>>> c

>>> c.days
0
>>> c.seconds
4
>>> c.microseconds

2 个答案:

答案 0 :(得分:12)

milliseconds = (c.days * 24 * 60 * 60 + c.seconds) * 1000 + c.microseconds / 1000.0

答案 1 :(得分:9)

或者,自2.7以来新:

c.total_seconds()*1000

https://docs.python.org/2/library/datetime.html