我已经阅读了一些关于此的帖子,并认为我有一些有效的代码。如果 2 个值之间的差异小于 1 秒,则显示的毫秒数是正确的。
如果差异超过一秒,它仍然只向我显示毫秒的差异。
如下。
正确的:
now_wind 2013-08-25 08:43:04.776209
first_time_wind 2013-08-25 08:43:04.506301
time_diff 0:00:00.269908
diff 269
错误 - 这应该是 2000 + 76?:
now_wind 2013-08-25 08:43:25.660427
first_time_wind 2013-08-25 08:43:23.583902
time_diff 0:00:02.076525
diff 76
#!/usr/bin/env python
import datetime
import time
from time import sleep
first_time_wind = datetime.datetime.now()
sleep (2)
now_wind = datetime.datetime.now()
print "now_wind", now_wind
print "first_time_wind", first_time_wind
time_diff_wind = (now_wind - first_time_wind)
print "time_diff", time_diff_wind
print "diff", time_diff_wind.microseconds / 1000