问Python中怎么将时间戳转换为指定格式日期?

答 1 个回答|327 次阅读
Coco老师 - 官方公众号:青少儿编程学习网
擅长:编程教育主页:https://kidscodes.cn/
import time 
  
timeStamp = 1646926800 
timeArray = time.localtime(timeStamp) 
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S",timeArray)
print(otherStyleTime)

结果:

2022-03-10 23:40:00

第二种方式:

import datetime 
timeStamp = 1646926800 
dateArray = datetime.datetime.utcfromtimestamp(timeStamp) 
otherStyleTime = dateArray.strftime("%Y-%m-%d %H:%M:%S")
print(otherStyleTime)

结果:

2022-03-10 15:40:00

推荐课程 »更多

    推荐知识

    Python精选库大全,青少年Python编程学习总结

    Python最适合青少儿编程进阶学习的编程语言