跳转到主要内容

扩展Python标准datetime模块

项目描述

dateutil - datetime 的强大扩展

pypi version supported Python version licence

Join the chat at https://gitter.im/dateutil/dateutil Read the documentation at https://dateutil.readthedocs.io/en/latest/

travis build status appveyor build status azure pipelines build status Code coverage

dateutil 模块为 Python 中的标准 datetime 模块提供了强大的扩展。

安装

dateutil 可以使用 pip 从 PyPI 安装(注意,包名与导入名不同)

pip install python-dateutil

下载

dateutil 可在 PyPI 上找到 https://pypi.ac.cn/project/python-dateutil/

文档托管在: https://dateutil.readthedocs.io/en/stable/

代码

代码和问题跟踪器托管在 GitHub 上: https://github.com/dateutil/dateutil/

特性

  • 计算相对差值(下个月、下一年、下周一、月中最后一周等);

  • 计算两个给定日期和/或 datetime 对象之间的相对差值;

  • 基于非常灵活的重复规则计算日期,使用 iCalendar 规范的超集。同时支持解析 RFC 字符串。

  • 几乎任何字符串格式日期的通用解析;

  • 为 tzfile(5) 格式文件(/etc/localtime、/usr/share/zoneinfo 等)、TZ 环境字符串(所有已知格式)、iCalendar 格式文件、给定范围(借助相对差值)、本地机器时区、固定偏移时区、UTC 时区以及基于 Windows 注册表的时区提供时区(tzinfo)实现。

  • 基于 Olson 数据库的内部最新世界时区信息。

  • 使用西方、东正教或儒略算法计算任何给定年份的复活节星期日日期;

  • 完整的测试套件。

快速示例

这里是一个快照,仅为了展示这个包的强大功能。更多示例请参阅文档。

假设你想知道在某个一年中,如果8月份有星期五的13号,下一个复活节还有多少年/月/日/等时间,你想要从“date” unix 系统命令中获取今天的日期。以下是代码

>>> 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

正好提前6个月真是 纯属巧合 :)

贡献

我们欢迎各种类型的贡献 - 错误报告、pull requests(代码、基础设施或文档修复)。有关如何为项目贡献的更多信息,请参阅存储库中的 CONTRIBUTING.md 文件。

作者

dateutil 模块由 Gustavo Niemeyer 编写于 2003 年 <gustavo@niemeyer.net>。

由以下人员维护:

从版本 2.4.1 开始,运行到 2.8.2,所有源代码和二进制分发都将由一个 PGP 密钥签名,该密钥至少被制作上一个发布版本的密钥签名。以下是发布签名密钥的表格

发布

签名密钥指纹

2.4.1-2.8.2

6B49 ACBA DCF6 BD1C A206 67AB CD54 FCE3 D964 BEFB

新发布 可能 有签名标签,但上传到 PyPI 的二进制和源代码分发将不再附带 GPG 签名。

联系

我们的邮件列表可在 dateutil@python.org 找到。由于它由 PSF 托管,因此受 PSF 行为准则 的约束。

许可证

2017年12月1日之后的所有贡献均采用双重许可发布 - 要么是 Apache 2.0 许可证BSD 3-Clause 许可证。2017年12月1日之前的贡献 - 除非明确重新许可 - 仅在 BSD 3-Clause 许可证下发布。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分布

python-dateutil-2.9.0.post0.tar.gz (342.4 kB 查看哈希值)

上传时间

构建分布

python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229.9 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面