为什么在 python 中 69 returns 1969 的两位数年份的 strptime?

why strptime for two digit year for 69 returns 1969 in python?

看下面的代码,

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

可选地如何实际克服这个问题并获得 2070?我将仅使用 2 位数年份进行检查。

Python 取决于平台的 C 库,它通常没有 2000 年的问题,因为所有日期和时间在内部都表示为自纪元以来的秒数。接受 struct_time 的函数通常需要 4 位数的年份。

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.

参考:Year 2000 (Y2K) issues in Python.