获取年、月、日

基本类型 / 日期和时间

from datetime import datetime

# A fixed moment: the output stays the same
moment = datetime(2027, 1, 1, 22, 13, 20)

# Month and day count from 1
year = moment.year
month = moment.month
day = moment.day
hour = moment.hour
minute = moment.minute
second = moment.second

# Monday is 1, Sunday is 7
iso_weekday = moment.isoweekday()

# Monday is 0, Sunday is 6
weekday = moment.weekday()

print(f"{moment = }")
print(f"{year = }")
print(f"{month = }")
print(f"{day = }")
print(f"{hour = }")
print(f"{minute = }")
print(f"{second = }")
print(f"{iso_weekday = }")
print(f"{weekday = }")