第一种방법:
Python代码
from datetime import datetime, timedelta
평일 = ['월요일','화요일','수요일',' 목요일',
'금요일', '토요일', '일요일']
def get_previous_byday(dayname, start_date=None):
start_date가 None인 경우:
> + day_num - day_num_target) % 7 if days_ago == 0: days_ago = 7 target_date = start_date - timedelta(days = days_ago) 반품 target_date print( datetime.today() ) print( get_previous_byday('Monday') ) print( get_previous_byday('Monday', datetime (2016, 8, 28)) ) 第二种方法,用dateutil模块Python代码 from datetime import datetime from dateutil. 상대델타 가져오기 상대델타 dateutil.rrule에서 가져오기 * d =datetime.now() 인쇄(d) 인쇄(d + relativedelta( weekday=FR)) print(d + relativedelta(weekday=FR(-1)))