Title: strptime not parsing some timezones
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: andrei.avk, belopolsky, docs@python, kj, martin.panter, r.david.murray, utkonos
Priority: normal Keywords:

Created on 2015-12-28 08:32 by utkonos, last changed 2021-09-07 15:34 by andrei.avk. This issue is now closed.

Messages (5)
msg257108 - (view) Author: Utkonos (utkonos) Date: 2015-12-28 08:32
I get a ValueError when running the following through strptime:

datetime.datetime.strptime('(CST)', '(%Z)')

But the following works:
datetime.datetime.strptime('(EST)', '(%Z)')

PST and MST also trigger the same exception.
msg257262 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-01-01 02:11
I suspect the datetime module’s %Z parsing depends on the locale, just like time.strptime() does: <>.
msg257294 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-01-01 20:24
The code is shared by the two modules (it's in  So, yes.

There is clearly a doc bug here (%Z needs a footnote in the table in the datetime docs), but there is no practical way to implement the parsing of arbitrary (non-locale) timezone strings, since it is not a one-to-one mapping.
msg399153 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-08-06 21:17
This was fixed so can be closed.

Current datetime docs have a footnote for %Z:

strptime() only accepts certain values for %Z:

any value in time.tzname for your machine’s locale

the hard-coded values UTC and GMT
msg401293 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2021-09-07 15:34
I'm closing this as fixed, the note in datetime docs is here:

(search for 'only accepts', - note 6)
Date User Action Args
2021-09-07 15:34:06andrei.avksetstatus: open -> closed

versions: + Python 3.9, - Python 2.7, Python 3.5, Python 3.6
nosy: + kj

messages: + msg401293
resolution: fixed
stage: resolved
2021-08-06 21:17:23andrei.avksetnosy: + andrei.avk
messages: + msg399153
2020-09-11 23:15:47brett.cannonsetnosy: - brett.cannon
2016-01-01 20:24:03r.david.murraysetversions: + Python 2.7, Python 3.6
nosy: + r.david.murray, docs@python

messages: + msg257294

assignee: docs@python
components: + Documentation
2016-01-01 02:11:19martin.pantersetnosy: + martin.panter
messages: + msg257262
2015-12-28 08:32:13utkonoscreate