This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2020年06月08日 10:00 by laurent chriqui, last changed 2022年04月11日 14:59 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg370971 - (view) | Author: laurent chriqui (laurent chriqui) | Date: 2020年06月08日 10:00 | |
When you use strftime with a 2 digit year i.e. '32' it outputs a '32' instead of '0032'. This prevents parsing the string again with the same format through strftime. Exemple: import datetime datetime_format="%Y" date=datetime.date(32,1,1) date_str=datetime.datetime.strftime(date, datetime_format) datetime.datetime.strptime(date_str, datetime_format) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime raise ValueError("time data %r does not match format %r" % ValueError: time data '32' does not match format '%Y' |
|||
| msg371019 - (view) | Author: Paul Ganssle (p-ganssle) * (Python committer) | Date: 2020年06月08日 17:07 | |
This is a duplicate of bpo-13305 and is due to platform-specific implementations of %Y. On Linux, `strftime()` does not zero-pad to 4, and if you need to represent years <1000, you should use "%4Y" to zero-pad the output. I think the ideal resolution would be a cross-platform implementation of strftime and strptime that does not rely on the system symbols, but that is a pretty large and overwhelming project. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:59:32 | admin | set | github: 85085 |
| 2020年06月08日 17:07:20 | p-ganssle | set | status: open -> closed superseder: datetime.strftime("%Y") not consistent for years < 1000 messages: + msg371019 resolution: duplicate stage: resolved |
| 2020年06月08日 14:48:20 | xtreak | set | nosy:
+ belopolsky, p-ganssle |
| 2020年06月08日 10:00:33 | laurent chriqui | create | |