計(jì)算某個(gè)時(shí)間距離當(dāng)天還有多少天有幾個(gè)周日
from datetime import datetime,timedelta
thatDay = "2020-10-01"
theDay = datetime.strptime(thatDay, "%Y-%m-%d") #XX日期轉(zhuǎn)換
today = datetime.now() #當(dāng)前日期
print(f"離{thatDay}還有{(theDay - today).days}天") #剩余日期
a = 0
for i in range((theDay - today).days):
thatDay = today + timedelta(days=i)
if thatDay.weekday() == 6:
# print(thatDay.strftime('%Y-%m-%d')) #出現(xiàn)周天日期
a += 1 #周天次數(shù)
print(f"有{a}個(gè)周天,可以放{a+a/2:.0F}天假")