classification
Title: strptime(%c) fails to parse the output of strftime(%c)
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, sam-s
Priority: normal Keywords:

Created on 2020-12-16 23:45 by sam-s, last changed 2020-12-17 01:56 by eric.smith. This issue is now closed.

Messages (2)
msg383217 - (view) Author: sds (sam-s) Date: 2020-12-16 23:45
>>> import datetime, locale
>>> locale.getlocale()
('en_US', 'UTF-8')
>>> datetime.datetime.strptime("%c",datetime.datetime.now().strftime("%c"))
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 '%c' does not match format 'Wed Dec 16 18:44:27 2020'
msg383218 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-12-17 01:52
You have the parameters to strptime backward.

>>> datetime.datetime.strptime(datetime.datetime.now().strftime("%c"), "%c")
datetime.datetime(2020, 12, 16, 20, 51, 38)
History
Date User Action Args
2020-12-17 01:56:02eric.smithsetstatus: open -> closed
type: behavior
resolution: not a bug
stage: resolved
2020-12-17 01:52:06eric.smithsetnosy: + eric.smith
messages: + msg383218
2020-12-16 23:45:29sam-screate