python 获取两个时间戳相差多少毫秒

code

import time
import datetime

t1=time.time()
time.sleep(0.02)
t2=time.time()

print("相差",(datetime.datetime.fromtimestamp(t2)-datetime.datetime.fromtimestamp(t1)).microseconds/1000.0,"ms")

 

 

 

 

 

 

 

 

 

posted @ 2020-11-27 19:13  anobscureretreat  阅读(2805)  评论(2编辑  收藏  举报