在调查期间,我将一些类似的方法与python文档重新绑定了datetime结合在一起,因此将我的建议留给我使用,以供任何绕行者使用:
# python3.7
import datetime
def get_week_start_date(yearweek: str) -> datetime:
"""
Return date of starting the week (Monday)
i.e: 201944 returns datetime.datetime(2019, 11, 4, 0, 0)
%G -> ISO 8601 year with century representing the year that contains the greater part of the ISO week (%V).
%u -> ISO 8601 weekday as a decimal number where 1 is Monday.
%V -> ISO 8601 week as a decimal number with Monday as the first day of the week. Week 01 is the week containing Jan 4.
Arguments:
yearweek {str} -- year to be calculated
Returns:
datetime -- Date of starting the week in passed year, week
"""
return datetime.datetime.strptime(f"{yearweek}-1", "%G%V-%u")