You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my view : is optional for %z, so it's not used in strftime(), while it's required in %:z.
If we enforce this, this actually allows something new instead of an alternative way to do it:
There should be one-- and preferably only one --obvious way to do it.
As dicussed, we need to have consistency across strptime and strftime, while keeping backwards compatibility.
%z and %:z work as expected in strftime, so no need to change anything there.
%z does what it should in strptime, while in addition allowing %:z-formatted strings too (see third comment). We should keep this behavior for backwards compatibility.
%:z fails in strptime. We should allow %:z there and make it parse only %:z-formatted strings.
Reacted by Nice Zombies, Zachary Vance, Paul Ganssle, Jan Kaliszewski and Jacob Willden
This was implemented for strftime without consideration for strptime in 023c51d 3 years ago. I would consider this a documentation bug, since it does imply it should be available on strptime also, but implementing it is a feature now.
Although this issue has been closed and the changes seem to be implemented and merged into main I still get the same error as on top of this discussion when using python3.14 (cpython implementation). In which python release should this change be available?
Thanks for any reply on this comment!
Activity
nineteendo commentedon Jul 1, 2024
Wouldn't
%:zhave to reject-0400?za3k commentedon Jul 1, 2024
Reasonable question. Shouldn't
%zreject-04:00? It doesn't, currently.Both should parse the alternative format, or neither, for the sake of consistency.
The current behavior for
%zis old (predates%:zfrom 3.12). I would argue for both to avoid breaking backwards compatibility.nineteendo commentedon Jul 1, 2024
In my view
:is optional for%z, so it's not used instrftime(), while it's required in%:z.If we enforce this, this actually allows something new instead of an alternative way to do it:
This should probably be labeled as a new feature.
za3k commentedon Jul 1, 2024
I think either implementation would be an improvement. I raise no objection :)
nineteendo commentedon Jul 1, 2024
@Eclips4 can you add the feature label?
LucasEsposito commentedon Jul 20, 2024
I'll be taking care of this one
As dicussed, we need to have consistency across
strptimeandstrftime, while keeping backwards compatibility.%zand%:zwork as expected instrftime, so no need to change anything there.%zdoes what it should instrptime, while in addition allowing%:z-formatted strings too (see third comment). We should keep this behavior for backwards compatibility.%:zfails instrptime. We should allow%:zthere and make it parse only%:z-formatted strings.pythongh-121237: Add %:z directive to strptime
pythongh-121237: Add %:z directive to strptime
LucasEsposito commentedon Jul 22, 2024
I added a PR addressing the issue: #122142
pythongh-121237: Add %:z directive to strptime
[-]Let strptime accept %:z[/-][+]Support `%:z` in `datetime.datetime.strptime`[/+]StanFromIreland commentedon Jun 29, 2025
This was implemented for strftime without consideration for strptime in 023c51d 3 years ago. I would consider this a documentation bug, since it does imply it should be available on strptime also, but implementing it is a feature now.
pythongh-121237: Add %:z directive to strptime
pythongh-121237: Add %:z directive to strptime
pythongh-121237: Add %:z directive to strptime
bn-jbischko commentedon Sep 13, 2025
Any reason why
strptimedoesn't return a datetime object with timezone, when%Zis used, either?Edit: Nevermind, see #66571
gh-121237: Add `%:z` directive to datetime.strptime (#136961)
pganssle commentedon Sep 19, 2025
This has now been implemented and merged in #136961
Iris-Hinrichs commentedon Sep 29, 2026
Although this issue has been closed and the changes seem to be implemented and merged into main I still get the same error as on top of this discussion when using python3.14 (cpython implementation). In which python release should this change be available?
Thanks for any reply on this comment!
StanFromIreland commentedon Sep 29, 2026
It was added to Python 3.15, which is to be released in two days.