py 时间处理
2024-10-19 03:47:52
字符串解析
如果你使用的不是isoformat string那么解析字符串就会失败,需要用strptime转换一下
import datetime
datetime.datetime.strptime('2021/2/5 9:34:37', '%Y/%m/%d %H:%M:%S')
# 标准的可以直接解析
datetime.datetime.fromisoformat('2021-02-05 09:34:37')
获取时间戳
datetime.datetime.fromisoformat('2021-02-05 09:34:37').timestamp()
最大值
print(
max(
datetime.datetime.fromisoformat('2021-02-05 01:00'),
datetime.datetime.fromisoformat('2021-02-06 01:00'),
datetime.datetime.fromisoformat('2021-02-07 01:00')))
当前时间
datetime.datetime.now()
datetime 类属性
datetime.datetime.now().year
datetime.datetime.now().month
datetime.datetime.now().day
replace
datetime.datetime.now().replace(year=2000).year # 2000
See also:
最新文章
- vim 学习积累(一)
- iphone手机不同版本兼容、横竖屏
- Oracle列操作(增加列,修改列,删除列)
- 组合数学 - 波利亚定理 --- poj : 2154 Color
- matplotlib库的常用知识
- centos7通过yum安装mysql,并授权远程连接
- Only the original thread that created a view hierarchy can touch its views
- java 复用类的三种方式区别 组合,继承,代理的区别
- Android L 之 RecyclerView 、CardView 、Palette
- 反应堆Reactor
- [转]iOS Anti-Debugging Protections
- UIView的基本属性及ANimation
- [OIDC in Action] 1. 基于OIDC(OpenID Connect)的SSO
- cshtml中正则表达式使用后台代码
- Python_匿名函数_47
- 批量杀掉多个pid文件中记录的pid进程, 并集成到shell脚本中
- 20190315xlVBA_删除无用的区域
- Extjs gridPanel可复制配置(转)
- java遇见的问题分析
- odoo开发笔记 -- odoo仪表板集成hightcharts