把时间戳进行转换为正常时间格式,代码如下:
import time
date=1584670171335
timeArray=time.localtime(temp)
otherStyleTime=time.strftime('%y--%m--%d %H:%M:%S',timeArray)
print(otherStyleTime)
返回错误
【原因】报错原因在date的长度,一般爬取下来的时间戳长度都是13位的数字,而time.localtime的参数要的长度是10位,所以我们需要将其/1000并取整即可。
修改如下:
import time
temp=1584670171335
timeArray=time.localtime(int(temp/1000)) #修改后代码
otherStyleTime=time.strftime('%y--%m--%d %H:%M:%S',timeArray)
print(otherStyleTime)