天天看點

Python 擷取指定日期是周幾 3種方法

Python 擷取指定日期是周幾 3種方法

from datetime import datetime
date =datetime.date(datetime(year=2020,month=7,day=26))
# 第一種,使用strftime("%w"), %w表示時,1-6表示周一到周六,0表示周日
print(date.strftime("%w"))
# 第二種,使用isoweekday()函數 1-7表示周一到周日
print(date.isoweekday())
# 第三種,使用weekday()函數,這裡是從0開始計數的,0-6表示周一到周日
print(date.weekday()+1)