http://blog.csdn.net/pipisorry/article/details/53067168

常用python自带时间处理模块

python自带的时间处理模块参考[操作系统服务:time时间模块+datetime模块 ]

有一些情况下,datetime却并没有那么好用。比如:

1.创建日期时间范围

2.创建未固定的日期时间

3.检验两个日期时间的差值是否在一定的范围内。

皮皮blog

dateutil模块

解析日期格式建议使用dateutil,不推荐使用datetime.datetime.strftime()。%Y 这种格式代表了某种具体的意义,但用着很麻烦。因此可以使用一个名为 dateutil 第三方包的 parser.parse() 函数实现自动转义,它几乎可以解析任何格式(这也可能会带来麻烦)。
>>> from dateutil.parser import parse
>>> parse('01-02-2010',dayfirst=True)

datetime.datetime(2010, 2, 1, 0, 0)

>>> parse('01-02-2010')
datetime.datetime(2010, 1, 2, 0, 0)
>>> parse('55')

datetime.datetime(2055, 6, 17, 0, 0)

The dateutil module provides powerful extensions tothe standard datetime module, available in Python.

>>> from dateutil.relativedelta import *
>>> from dateutil.easter import *
>>> from dateutil.rrule import *
>>> from dateutil.parser import *
>>> from datetime import *
>>> now = parse("Sat Oct 11 17:13:46 UTC 2003")
>>> today = now.date()
>>> year = rrule(YEARLY,dtstart=now,bymonth=8,bymonthday=13,byweekday=FR)[0].year
>>> rdelta = relativedelta(easter(year), today)
>>> print("Today is: %s" % today)
Today is: 2003-10-11
>>> print("Year with next Aug 13th on a Friday is: %s" % year)
Year with next Aug 13th on a Friday is: 2004
>>> print("How far is the Easter of that year: %s" % rdelta)
How far is the Easter of that year: relativedelta(months=+6)
>>> print("And the Easter of that year is: %s" % (today+rdelta))
And the Easter of that year is: 2004-04-11

计算时间差的示例

其中中间lz加了一个timestamp的转换(为了输入到只接收整形数的函数中),直接不转换也可以。

from dateutil.parser import parse
import datetimea = 'Sat Jul 31 20:15:24 +0000 2011'
b = 'Sat Jul 30 20:07:44 +0000 2011'
# print(parse(a))
aa = datetime.datetime.timestamp(parse(a))
bb = datetime.datetime.timestamp(parse(b))
print(datetime.datetime.fromtimestamp(aa) - datetime.datetime.fromtimestamp(bb))
print((datetime.datetime.fromtimestamp(aa) - datetime.datetime.fromtimestamp(bb)).total_seconds() / 3600)

[dateutil - powerful extensions to datetime]

Delorean:解决 Python 中有关日期处理的棘手问题的库

Delorean是一个非常酷的日期/时间库。这个项目由Mahdi Yusuf维护,类似JavaScript的moment,拥有非常完善的技术文档。

用它处理日期和时间非常方便。设置时区,截取到秒、分、小时,甚至使用特定步骤从一个日期进到另一个日期。文档里面有很多例子。

用Python处理时间有点痛苦。如果你用Python的标准时间库datetime,并且处理过时区,你会感到绝望。delorean提供了一个相比于datetime和pytz的更好的抽象,让你处理时间更容易。它有很多有用的处理时区的特性,标准化时区或者从一个时区改变到另外一个时区。

from delorean import Delorean  
    EST = "US/Eastern"  
    d = Delorean(timezone=EST)

[Delorean英文文档]

皮皮blog

其它时间相关的库

pytz python时区处理模块(同时也包括夏令时)。世界时区,使用tz database时区信息数据库。

arrow,更好的日期和时间处理Python库。

chronyk,一个Python 3版函数库,用于解析人写的时间和日期。

moment,类似Moment.js的日期/时间Python库。

radar,雷达,生成随机日期/时间。

sandglass(沙漏)** 是一个增强的、友好的时间处理库,目的是为了解放程序员的生产力。在python中有太多处理时间的库,datetime/date/time/calendar等等。需要记的细节太多,选择困难。而sandglass就是解决这个的青霉素。从各种麻烦的转换中解脱出来。只需记住 **Sandglass对象** 和 **ben()** 、 **tslice()** 、 **cronwalk()** 这几个主要的api即可。[sandglass 0.0.1]

Python日期时间处理: datestuff

[Python日期时间处理: datestuff]

[datestuff github]

when.py

友好的时间日期库

>>> import when
>>> when.timezone()
'Asia/Shanghai'
>>> when.today()
datetime.date(2013, 5, 14)
>>> when.tomorrow()
datetime.date(2013, 5, 15)
>>> when.now()
datetime.datetime(2013, 5, 14, 21, 2, 23, 78838)

[https://github.com/dirn/When.py]

皮皮blog

from: http://blog.csdn.net/pipisorry/article/details/53067168

ref: [Python时间库性能比较]

python模块:时间处理模块相关推荐

  1. python中处理日期和时间的标准模块是-关于时间和Python的时间处理模块

    概念 关于时间你因该了解的几个概念: 秒 在1967年的第13届国际度量衡会议上决定以原子时定义的秒作为时间的国际标准单位:铯133原子基态的两个超精细能阶间跃迁对应辐射的9,192,631,770个 ...

  2. Python 获取时间——time 模块

    文章目录 time模块 1. time.localtime() 2. time.time() 3. time.mktime(t) 4. time.asctime() 5. time.ctime() 6 ...

  3. python时间处理模块datetime+dateutil、numpy时间处理模块datetime64以及pandas时间处理模块Timestamp的演化路径及常用处理接口

    python时间处理模块datetime+dateutil.numpy时间处理模块datetime64以及pandas时间处理模块Timestamp及常用处理接口 python时间处理模块dateti ...

  4. python中time模块中的倒计时_Python中time模块与datetime模块在使用中的不同之处 python 的time模块获取的是什么时间...

    python的datetime模块的一些问题 time_1 = datetime.datetime.now(pytz.timezone('Asia/Shanghai')) timeimport dat ...

  5. 【转载】Python日期时间模块datetime详解与Python 日期时间的比较,计算实例代码

    本文转载自脚本之家,源网址为:https://www.jb51.net/article/147429.htm 一.Python中日期时间模块datetime介绍 (一).datetime模块中包含如下 ...

  6. python学习之老男孩python全栈第九期_day019知识点总结——collections模块、时间模块、random模块、os模块、sys模块...

    一. collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:namedtuple.deque.Counte ...

  7. python中时间模块datetime总结

    python关于时间模块,做一下总结 1.常用参数: # %y 两位数的年份表示(00-99) # %Y 四位数的年份表示(000-9999) # %m 月份(01-12) # %d 月内中的一天(0 ...

  8. python当中时间模块详解,包括time,timeit,datatime

    目录 time 模块 -- 时间获取和转换 以下三个比较常见: time.perf_counter() time.process_time() time.sleep(secs) timeit 模块详解 ...

  9. Python之日期与时间处理模块(date和datetime)

    本节内容 前言 相关术语的解释 时间的表现形式 time模块 datetime模块 时间格式码 总结 前言 在开发工作中,我们经常需要用到日期与时间,如: 作为日志信息的内容输出 计算某个功能的执行时 ...

  10. python中时间模块

    时间日期相关的模块 calendar 日历模块 time 时间模块 datetime 日期时间模块 timeit 时间检测模块 日历模块 calendar() 功能:获取指定年份的日历字符串 格式:c ...

最新文章

  1. 只要工具到位,java也可以很简单
  2. spring boot 扩展之AutoConfigurationImportListener
  3. 使用EasyPoi导出Excel
  4. TabError- inconsistent use of tabs and spaces in indentation 查验及解决方法
  5. 替换jar包_替换代码的情况下不停机!这操作可能工作6年的Java程序员都不会
  6. python的诞生和发展历史_Python发展史-一门编程语言的起源
  7. 山东大学计算机学院交叉,Xueying Qin
  8. 小程序入门学习16--上传小程序至github
  9. 江苏职称计算机考试错做题,江苏省职称计算机考试word注意点.doc
  10. mysql中的表显示“使用中”解决办法!
  11. 用力和应变片计算弹性模量_电阻应变片粘贴及弹性模量的测定实验报告徐姗.doc...
  12. 软件定义存储正当时 厂商纷纷争抢一杯羹
  13. 鲁迅《狂人日记》全文
  14. 第7课用计算机写作文优质课例,有趣的电脑课作文9篇
  15. 16个最佳WordPress登录页面插件
  16. 3个技术男搞恋爱版 ChatGPT,估值70亿...
  17. 在canvas上实现3D效果
  18. windows系统电脑间互传文件
  19. 使用CStdioFile操作文件和filetxt.cpp报错和filecore.cpp报错
  20. word表格标题和表格如何不分开

热门文章

  1. 内容分发网络CDN(互联网技术)
  2. 【排序】内部排序算法实现
  3. Spring Security笔记:Remember Me(下次自动登录)
  4. php 之 json格式
  5. JNI系列(2):jstring操作
  6. (对比PDF)Adobe Acrobat DC 离线对比PDF、draftable.com/compare 在线对比PDF
  7. 基准对象object中的基础类型----元组 (五)
  8. [JLOI2008] CODES
  9. struts2 result随笔
  10. sshj ,ssh , springmvc pom.xml