python生成毫秒级时间戳

import time
import datetime
timestamp=time.time()
time_local = time.localtime(timestamp)
d = datetime.datetime.fromtimestamp(timestamp)
# 精确到毫秒
str1 = d.strftime("%Y-%m-%d %H:%M:%S.%f")[0:23] #使用切片的方式使精度只到小数点后三位
print(str1)
posted @ 2021-05-25 16:35  道悬  阅读(2764)  评论(0)    收藏  举报