This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: datetime.strptime %Z doesn't produce aware object
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, belopolsky, lilydjwg
Priority: normal Keywords:

Created on 2016-10-31 05:48 by lilydjwg, last changed 2022-04-11 14:58 by admin.

Messages (2)
msg279761 - (view) Author: lilydjwg (lilydjwg) * Date: 2016-10-31 05:48
With %z, the result gets a tzinfo, but with %Z, it succeeds but the result is without timezone info:

>>> datetime.datetime.strptime('2016-10-31T03:58:24 CST', '%Y-%m-%dT%H:%M:%S %Z')
datetime.datetime(2016, 10, 31, 3, 58, 24)
>>> datetime.datetime.strptime('2016-10-31T03:58:24 +0800', '%Y-%m-%dT%H:%M:%S %z')
datetime.datetime(2016, 10, 31, 3, 58, 24, tzinfo=datetime.timezone(datetime.timedelta(0, 28800)))

So the first one loses infomation (and will result in wrong values if the programmer isn't aware of this, and the local timezone is different than the one in the string).
msg279775 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-10-31 09:43
According to documentation %z is the only directive that would result in the aware object. %Z is not capable of doing that, so what you're asking is a new feature - that could only go in 3.7
History
Date User Action Args
2022-04-11 14:58:38adminsetgithub: 72751
2016-10-31 09:43:41SilentGhostsettype: behavior -> enhancement
title: datetime.strptime %Z doesn't get included in the result -> datetime.strptime %Z doesn't produce aware object
components: + Library (Lib)

nosy: + SilentGhost
versions: + Python 3.7
messages: + msg279775
2016-10-31 06:50:50xiang.zhangsetnosy: + belopolsky
2016-10-31 05:48:57lilydjwgcreate