python学习-将一串数字形式的时间转换为标准时间格式


@python 将一串数字形式的时间转换为标准时间格式!!!
1.首先,确定你的那一串时间是10位还是13位的,
如果是10位请看方案一,13位请看解决方案二。
方案一:
10位的数字表示的是秒时间戳。

import time
time.time()#获取当前的秒时间戳

通过下边的代码就可以将10位的秒时间戳抓换为标准输出格式

import time
tupTime = time.localtime(1566366555)#秒时间戳
stadardTime = time.strftime("%Y-%m-%d %H:%M:%S", tupTime)
print(stadardTime)
#2019-08-21 13:49:15

方案二
13位的数字串是毫秒级别的时间戳,通过下边的代码转换为表转格式:

import time
timeNum=1566366547705#毫秒时间戳
timeTemp = float(timeNum/1000)
tupTime = time.localtime(timeTemp)
stadardTime = time.strftime("%Y-%m-%d %H:%M:%S", tupTime)
print(stadardTime)
#2019-08-21 13:49:07

参考:
https://blog.csdn.net/qq_38486203/article/details/80239762
在线时间转换工具:https://tool.lu/timestamp


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM