今天小编就为大家分享一篇关于Python计算时间间隔(精确到微妙)的代码实例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
使用python中的datetime
import datetime oldtime=datetime.datetime.now() print oldtime; x=1 while x<10000000: x=x+1 newtime=datetime.datetime.now() print newtime; u'相差:%s'%(newtime-oldtime) u'相差:%s微秒'%(newtime-oldtime).microseconds u'相差:%s秒'%(newtime-oldtime).seconds< pre>
结果如下:
总结
以上就是Python计算时间间隔(精确到微妙)的代码实例的详细内容,更多请关注0133技术站其它相关文章!