脚本宝典收集整理的这篇文章主要介绍了Python 转换时间戳为指定格式日期,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我们将会启用到time库:
import time # 获得当前时间时间戳 now = int(time.time()) #转换为其他日期格式,如:"%Y-%m-%d %H:%M:%S" timeArray = time.localtime(now) otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) PRint(otherStyleTime)
2019-05-21 18:02:49
import datetime # 获得当前时间 now = datetime.datetime.now() # 转换为指定的格式 otherStyleTime = now.strftime("%Y-%m-%d %H:%M:%S") print(otherStyleTime)
2019-05-21 18:03:48
import time timeStamp = 1557502800 timeArray = time.localtime(timeStamp) otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) print(otherStyleTime)
2019-05-10 23:40:00
import datetime timeStamp = 1557502800 dateArray = datetime.datetime.utcFromtimestamp(timeStamp) otherStyleTime = dateArray.strftime("%Y-%m-%d %H:%M:%S") print(otherStyleTime)
本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注脚本宝典的更多内容!
以上是脚本宝典为你收集整理的Python 转换时间戳为指定格式日期全部内容,希望文章能够帮你解决Python 转换时间戳为指定格式日期所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。