3 Star 0 Fork 1

mirrors_trekhleb/learn-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_datetime.py 1015 Bytes
一键复制 编辑 原始数据 按行查看 历史
Oleksii Trekhleb 提交于 2018-08-29 23:23 +08:00 . Add Python scripts.
"""Dates and Times.
@see: https://docs.python.org/3/tutorial/stdlib.html#dates-and-times
The datetime module supplies classes for manipulating dates and times in both simple and complex
ways. While date and time arithmetic is supported, the focus of the implementation is on efficient
member extraction for output formatting and manipulation. The module also supports objects that
are timezone aware.
"""
from datetime import date
def test_datetime():
"""Dates and Times"""
real_now = date.today()
assert real_now
fake_now = date(2018, 8, 29)
assert fake_now.day == 29
assert fake_now.month == 8
assert fake_now.year == 2018
assert fake_now.ctime() == 'Wed Aug 29 00:00:00 2018'
assert fake_now.strftime(
'%m-%d-%y. %d %b %Y is a %A on the %d day of %B.'
) == '08-29-18. 29 Aug 2018 is a Wednesday on the 29 day of August.'
# Dates support calendar arithmetic.
birthday = date(1964, 7, 31)
age = fake_now - birthday
assert age.days == 19752
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_trekhleb/learn-python.git
git@gitee.com:mirrors_trekhleb/learn-python.git
mirrors_trekhleb
learn-python
learn-python
master

搜索帮助