【Python】时间与时间戳

code

import time

#获取10位时间戳
t=time.time()
print(int(t))

#获取13位时间戳
temp=time.time()
timestamp=int(round(temp*1000))
print(timestamp)

#日期转时间戳
dt="2020-12-29 18:13:21"
timearray=time.strptime(dt,"%Y-%m-%d %H:%M:%S")
timestamp=time.mktime(timearray)
tmp_stamp=int(timestamp)
print(tmp_stamp)

 输出

macname@MacdeMacBook-Pro Desktop % python3 xxxxx.py 
1609237378
1609237378025
1609236801
macname@MacdeMacBook-Pro Desktop % 

 

 

 

 

 

 

 

 

posted @ 2020-12-29 18:21  anobscureretreat  阅读(115)  评论(0编辑  收藏  举报