[issue38139] [BUG] datetime.strptime could not handle timezone
Yixing Jiang
report at bugs.python.org
Thu Sep 12 09:48:05 EDT 2019
New submission from Yixing Jiang <johnestar.wag at gmail.com>:
datetime.datetime.strptime throws out an error for me, to reproduce, use the following block:
```
>>> import datetime
>>> import pytz
>>> d2 = datetime.datetime(2019, 9, 11, 18, 35, 17, 334000, tzinfo=pytz.timezone('CET'))
>>> d2.strftime('%Y%m%d%H%M%S%f%Z')
'20190911183517334000CET'
>>> datetime.datetime.strptime('20190911183517334000CET', '%Y%m%d%H%M%S%f%Z')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/conda/envs/lab42/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
tt, fraction = _strptime(data_string, format)
File "/opt/conda/envs/lab42/lib/python3.6/_strptime.py", line 362, in _strptime
(data_string, format))
ValueError: time data '20190911183517334000CET' does not match format '%Y%m%d%H%M%S%f%Z'
>>> datetime.datetime.strptime('20190911183517334000', '%Y%m%d%H%M%S%f')
datetime.datetime(2019, 9, 11, 18, 35, 17, 334000)
```
so strptime could only handle the format without %Z.
----------
components: Library (Lib)
messages: 352163
nosy: Yixing Jiang
priority: normal
severity: normal
status: open
title: [BUG] datetime.strptime could not handle timezone
type: crash
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38139>
_______________________________________
More information about the Python-bugs-list
mailing list