字符串解析

如果你使用的不是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:

最新文章

  1. vim 学习积累(一)
  2. iphone手机不同版本兼容、横竖屏
  3. Oracle列操作(增加列,修改列,删除列)
  4. 组合数学 - 波利亚定理 --- poj : 2154 Color
  5. matplotlib库的常用知识
  6. centos7通过yum安装mysql,并授权远程连接
  7. Only the original thread that created a view hierarchy can touch its views
  8. java 复用类的三种方式区别 组合,继承,代理的区别
  9. Android L 之 RecyclerView 、CardView 、Palette
  10. 反应堆Reactor
  11. [转]iOS Anti-Debugging Protections
  12. UIView的基本属性及ANimation
  13. [OIDC in Action] 1. 基于OIDC(OpenID Connect)的SSO
  14. cshtml中正则表达式使用后台代码
  15. Python_匿名函数_47
  16. 批量杀掉多个pid文件中记录的pid进程, 并集成到shell脚本中
  17. 20190315xlVBA_删除无用的区域
  18. Extjs gridPanel可复制配置(转)
  19. java遇见的问题分析
  20. odoo开发笔记 -- odoo仪表板集成hightcharts

热门文章

  1. loj10010糖果传递
  2. python 利用正则表达式获取IP地址
  3. HttpClient之基本使用
  4. ness使用-漏扫
  5. Educational Codeforces Round 84 (Div. 2)
  6. 【bzoj 2339】[HNOI2011]卡农(数论--排列组合+逆元+递推)
  7. Equal Numbers Gym - 101612E 思维
  8. int和longlong的范围
  9. hdu1263 水果
  10. HDU - 3281 dp