forked from australiaitgroup/learn-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_datetime.py
More file actions
42 lines (30 loc) · 1.34 KB
/
Copy pathtest_datetime.py
File metadata and controls
42 lines (30 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Dates and Times.
日期和时间 (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.
datetime 模块提供了用于以简单或复杂方式操作日期和时间的类。
虽然支持日期和时间的算术运算,但实现的重点在于高效地提取成员以用于
输出格式化和操作。该模块还支持时区感知的对象。
"""
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