天天看点

实例016:输出日期 输出指定格式的日期。

实例016:输出日期

 代码复现:

# 输出指定格式的日期。
import datetime

print(datetime.date.today())  # 输出今天的日期

print(datetime.date(2333, 2, 3))  # 输出指定日期 年-月-日

print(datetime.date.today().strftime('%d/%m/%Y'))  # 输出今天的日期 格式转为日/月/年

day = datetime.date(1111, 2, 3)
day = day.replace(year=day.year + 22)  # 年份1111+22年
print(day)      

运行结果:

2022-07-08
2333-02-03
08/07/2022
1133-02-03

Process finished with exit code 0