问题
Look at the following code,
def expdate(date):
_exp_date = datetime.strptime(date, "%m%y")
>>> expdate('1268')
2068-12-01 00:00:00
>>> expdate('1269')
1969-12-01 00:00:00
Optionally how to actually overcome this and get 2070 ? I'll be checking only using 2 digits years.
回答1:
Python depends on the platform’s C library, which generally doesn’t have year 2000 issues, since all dates and times are represented internally as seconds since the epoch. Functions accepting a struct_time generally require a 4-digit year.
When 2-digit years are accepted, they are converted according to the POSIX or X/Open standard: values 69-99 are mapped to 1969-1999, and values 0–68 are mapped to 2000–2068.
Refer: Year 2000 (Y2K) issues in Python.
来源:https://stackoverflow.com/questions/61500557/why-strptime-for-two-digit-year-for-69-returns-1969-in-python