python中的time.time()就是时间戳
代码:
import time
time_stamp = time.time()
print(time_stamp)
time_array = time.localtime(time_stamp)
other_way_time = time.strftime("%Y-%m-%d %H:%M:%S", time_array)
print(other_way_time)
结果:
1610608539.8310502
2021-01-14 15:15:39
当然很多时候时间戳会记录整数,需要进行int
import time
time_stamp = int(time.time())
print(time_stamp)
结果:
1610608841