import time
#时间戳:1970-01-01 00:00:00 到当前时间的秒数(10位数)或者是毫秒数(13位)
#timestamp=1559223244110
timestamp=int(time.time())*1000
print(timestamp)
timearray=time.localtime(float(timestamp/1000))
tt=time.strftime('%Y-%m-%d %H:%M:%S',timearray)
print(tt)
结果如下:
1573099239000
2019-11-07 12:00:39
import time
def get_time_stamp():
now = int(round(time.time()*1000))
time_stamp = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(now/1000))
print(time_stamp)
stamp = ("".join(time_stamp.split()[0].split("-"))+"".join(time_stamp.split()[1].split(":"))).replace('.', '')
print(stamp)
if __name__ == '__main__':
get_time_stamp()
结果如下:
2019-11-07 11:56:31
20191107115631