Skip to content

Instantly share code, notes, and snippets.

@luzihang123
Last active October 25, 2019 08:40
Show Gist options
  • Save luzihang123/f32c46b5c0d2a2436f20ffde679c894e to your computer and use it in GitHub Desktop.
Save luzihang123/f32c46b5c0d2a2436f20ffde679c894e to your computer and use it in GitHub Desktop.
计算临近(包含今天)的星期几的日期
import calendar
import datetime
choose_week = {'1': 'MONDAY',
'2': 'TUESDAY',
'3': 'WEDNESDAY',
'4': 'THURSDAY',
'5': 'FRIDAY',
'6': 'SATURDAY',
'7': 'SUNDAY', }
s = "6" # 计算临近(包含今天)的星期六的日期
def get_next_week():
'''
计算临近(包含今天)的星期几的日期
'''
today = datetime.date.today()
print(today)
one_day = datetime.timedelta(days=1)
m1 = eval(f"calendar.{choose_week[s]}")
print(m1, today.weekday())
while today.weekday() != m1:
today += one_day
next_week = today.strftime('%Y-%m-%d')
return next_week
print(get_next_week())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment