Python之时间戳
以下为时间戳的具体使用方法。
import time
print(datetime.datetime.now())
2022-06-28 17:22:45.85818
获取10位时间戳
print(int(time.time()))
获取13位时间戳 (round()是四舍五⼊)
print(round(time.time()*1000))
对time时间戳转为为字符串
t = round(time.time()*1000)
t_str = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(t/1000))
print(type(t_str))
2022-06-28 16:50:58
t = round(time.time()*1000)
t_str = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(t/1000))
print(t_str)
2022-06-28 12:29:08;
print(datetime.datetime.now())
2022-06-28 17:15:36.981650
ppp = time.time() * 1000
print(round(ppp))
print(ppp)
print(int(ppp))
1656407736982
1656407736981.6504
1656407736981