很抱歉是否有这样的话题,但我不知道如何提出问题以找到类似的话题。正如我所说的,它将获得201900,而我需要201852。有什么建议吗?谢谢!
from dateutil.relativedelta import relativedelta
year = str(current_date.isocalendar()[0])
wk = str(current_date.isocalendar()[1])
weektoday = year+'0'+wk
neededwk = datetime.datetime.strptime(weektoday, '%Y%w%W')
if datetime.date.today().isoweekday() == 1:
neededwk = neededwk - relativedelta(weeks=2)
else:
neededwk = neededwk - relativedelta(weeks=1)
neededwk = neededwk.strftime('%Y%W')
有关详细信息:relativedelta