Python怎样转换时间戳为日期,方法是啥
Admin 2022-05-21 群英技术资讯 522 次浏览
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)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
在本文中,我们将一起探索几种从图像中提取颜色、形状和纹理特征的方法,这些方法基于处理图像的经验,感兴趣的小伙伴可以了解一下
今天小编给大家分享10个Python高级脚本,帮助我们减少无谓的时间浪费,提高工作学习中的效率。文中示例代码讲解详细,需要的可以参考一下
本篇文章给大家带来了关于Python的相关知识,其中主要整理了编码规范的相关问题,想要写好python代码,必须了解python相关编码规范,有了这个的加持,编写的代码不仅可以实现相应的
动机从一个问题引出 MetaClassMetaclass 编程动机python语言因为工作偏向于 AI ,所以对于这门语言还停留在表面,对于 python 深层并没有接触到。今天来聊一聊元类(metacla
这篇文章主要介绍了python中not not x 与 bool(x) 的区别,我们就来做一个选择,就是 not not x 和 bool(x) 用哪个比较好?下面一起进入文章看看吧</P><P>
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008