其他分享
首页 > 其他分享> > 时间戳的格式化

时间戳的格式化

作者:互联网

# 使用time
timeStamp = 1381419600
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y--%m--%d %H:%M:%S", timeArray)
print(otherStyleTime) # 2013--10--10 23:40:00
# 使用datetime
timeStamp = 1381419600
dateArray = datetime.datetime.fromtimestamp(timeStamp)
otherStyleTime = dateArray.strftime("%Y--%m--%d %H:%M:%S")
print(otherStyleTime) # 2013--10--10 23:40:00
# 使用datetime,指定utc时间,相差8小时
timeStamp = 1381419600
dateArray = datetime.datetime.utcfromtimestamp(timeStamp)
otherStyleTime = dateArray.strftime("%Y--%m--%d %H:%M:%S")
print(otherStyleTime) # 2013--10--10 15:40:00

标签:10,00,格式化,timeStamp,otherStyleTime,40,datetime,时间
来源: https://www.cnblogs.com/yp19970/p/12335398.html