New submission from Akira Li:
>>> from datetime import datetime, timezone
>>> dt = datetime.now(timezone.utc)
>>> fmt = '%Y-%m-%d %H:%M:%S.%f %Z%z'
>>> datetime.strptime(dt.strftime(fmt), fmt)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/cpython/Lib/_strptime.py", line 500, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/cpython/Lib/_strptime.py", line 337, in _strptime
(data_string, format))
ValueError: time data '2014-08-21 11:29:13.537251 UTC+00:00+0000'
does not match format '%Y-%m-%d %H:%M:%S.%f %Z%z'
The issue is that dt.strftime('%Z') produces 'UTC+00:00'
(due to timezone.utc.tzname(dt) returning 'UTC+00:00')
instead of 'UTC' that strptime() accepts and %Z examples [1]
in the docs demonstrate.
[1]
https://docs.python.org/3.4/library/datetime.html#strftime-and-strptime-behavior
----------
components: Library (Lib)
messages: 225606
nosy: akira
priority: normal
severity: normal
status: open
title: strftime/strptime round trip fails even for UTC datetime object
type: behavior
versions: Python 3.4, Python 3.5
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue22241>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com