系统:Windows 7 语言版本:Anaconda3-4.3.0.1-Windows-x86_64 编辑器:pycharm-community-2016.3.2 Python:3.6.0
Part 1:实现功能
Part 2:代码
import datetime
current_time = datetime.datetime.now()print(current_time)
n = 3time_delta = datetime.timedelta(days=n)other_time_1 = current_time + time_deltaother_time_2 = current_time - time_delta
# 获取年、周次、星期几y, w, d = current_time.isocalendar()print("今天对应的年,周次,星期几:", y, w, d)
y, w, d = other_time_1.isocalendar()print("3天后对应的年,周次,星期几:", y, w, d)
y, w, d = other_time_2.isocalendar()print("3天前对应的年,周次,星期几:", y, w, d)
代码截图
运行结果
Part 3:部分代码解读
current_time.isocalendar()
,返回一个元组,分别为年、周次、星期x = current_time.isocalendar()
print(x)
print(type(x))
运行结果