天天看點

執行個體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