Python 官方文档:入门教程 => 点击学习
开发过程中最常用的时间处理就是获取时间戳,获取当前日期,或者时间戳,日期互转,做个总结,免得总找不着。1、获取当前timestamp>>> from time import time >>> time()
开发过程中最常用的时间处理就是获取时间戳,获取当前日期,或者时间戳,日期互转,做个总结,免得总找不着。
1、获取当前timestamp
>>> from time import time
>>> time()
1423023221.585132
2、获取当前日期
>>> from time import localtime,strftime,time
>>> strftime("%Y-%m-%d %H:%M:%S",localtime())
'2015-02-04 12:13:07'
# 获取当前UTC时间
time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
3、日期的计算
获取昨天的日期
>>> from time import localtime,strftime,time
>>> strftime("%Y-%m-%d %H:%M:%S",localtime(time()-60*60*24))
'2015-02-03 12:14:21'
4、日期转时间戳
>>> from time import mktime,strptime
>>> mktime(strptime("2015-02-04 11:57:11","%Y-%m-%d %H:%M:%S"))
1423022231.0
--结束END--
本文标题: Python 日期时间处理
本文链接: https://www.lsjlt.com/news/185094.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0