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

為{幸葍}努か 提交于 2021-02-11 14:47:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!