Message225606
>>> 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 |
|
Date |
User |
Action |
Args |
2014-08-21 11:35:17 | akira | set | recipients:
+ akira |
2014-08-21 11:35:17 | akira | set | messageid: <1408620917.6.0.856660367054.issue22241@psf.upfronthosting.co.za> |
2014-08-21 11:35:17 | akira | link | issue22241 messages |
2014-08-21 11:35:16 | akira | create | |
|