Title: [doc] time.strftime %z format specifier is the same as %Z
Type: enhancement Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.11
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Mike.Owens, SilentGhost, brett.cannon, dendory, docs@python, hugovk, iritkatriel, miss-islington, r.david.murray
Priority: normal Keywords: easy, patch

Created on 2014-01-16 18:35 by Mike.Owens, last changed 2022-01-15 09:27 by iritkatriel. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30354 merged hugovk, 2022-01-03 11:32
PR 30608 merged miss-islington, 2022-01-14 22:49
PR 30609 merged miss-islington, 2022-01-14 22:49
Messages (16)
msg208295 - (view) Author: Mike Owens (Mike.Owens) Date: 2014-01-16 18:35
When using strftime from the time module on 64bit Python for Windows the format specifier %z gives the time zone name instead of the time zone offset as stated in the documentation.

>>> strftime("%z")
'US Mountain Standard Time'
>>> strftime("%Z")
'US Mountain Standard Time'

The expected output for my time zone is -7:00.
msg208296 - (view) Author: Mike Owens (Mike.Owens) Date: 2014-01-16 18:39
Expected output should be -0700.

I checked Python 3.3.1 and 2.7.4 on Linux and the output is as expected.
msg208298 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-01-16 19:06
Please see the footnote on the 'time' documentation page.  It sounds like Windows is treating %z as if was %Z.

There should be a reference to that footnote from the %z table entry, so that's a doc bug.  Might also be worth explicitly mentioning this weird Windows behavior.

FYI, you can use the strftime functionality of the datetime module to get cross platform %z support.
msg208299 - (view) Author: Mike Owens (Mike.Owens) Date: 2014-01-16 19:14
Documentation doesn't have a foot note for either %z or %Z but there is generic footnote talking about C lib behavior and that %z is deprecated. I guess if there were a foot note in the table for %z that would save some time for everyone.
msg208300 - (view) Author: Mike Owens (Mike.Owens) Date: 2014-01-16 19:25
The datetime.strftime function produces no output for %z or %Z. Very irritating.
msg208301 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2014-01-16 19:29
Mike, the note is at the very bottom of the page.

datetime.strftime produces empty strings with this specifiers for naïve objects, are the object you're testing timezone-aware?
msg208308 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-01-16 20:36
The %z table entry exists only in the 3.4 (dev) docs, not the 3.3 docs.  There is no doc change needed for 3.3, since it doesn't mention %z except in the footnote.

And yes, I should have mentioned that the datetime versions only work with aware timezones.  You can get an aware local time from email.utils.localtime().  (This localtime function may eventually move to
the datetime module if it can be made more reliable, but it works fine for the use cases the email package needs.)
msg208309 - (view) Author: Mike Owens (Mike.Owens) Date: 2014-01-16 20:39
I'm looking right at the 3.3 docs right now. %z is in the table. 

8.1.8. strftime() and strptime() Behavior
msg208310 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-01-16 20:41
Ah, you are correct.  I'm not sure what page I was looking at before.  Maybe I hadn't switched away from the python2 page.
msg245864 - (view) Author: (dendory) Date: 2015-06-26 20:14
Why is the focus on documentation entries when the real work should be on trying to make this function to work on all platforms?

I understand that Windows's implementation of strftime() defines %z and %Z to return the same thing, but timezone information is still available in other ways. For example, _get_timezone() returns the offset in seconds between localtime and UTC. I don't have VC++ 2010 installed so I can't test it but this seems like a fairly simple thing to fix. Just take that result and multiply.

msg245865 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-06-26 20:25
Because there's a different issue for making strftime system independent, issue 3173.
msg407206 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-11-28 13:17
Seems like the only thing to do on this issue is to add a reference to the footnote in the table entries for %z and %Z.
msg407367 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-11-30 12:05
See also Issue29964.
msg410604 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2022-01-14 22:49
New changeset 305588c67cdede4ef127ada90c1557bc1ef7c200 by Hugo van Kemenade in branch 'main':
bpo-20281, bpo-29964: update datetime docs to refer %z and %Z to a pre-existing footnote (GH-30354)
msg410608 - (view) Author: miss-islington (miss-islington) Date: 2022-01-14 23:59
New changeset 93dc1654dc3c925c062e19f0ef8587aa8961ef8a by Miss Islington (bot) in branch '3.10':
bpo-20281, bpo-29964: update datetime docs to refer %z and %Z to a pre-existing footnote (GH-30354)
msg410610 - (view) Author: miss-islington (miss-islington) Date: 2022-01-15 00:00
New changeset f869b56fe4be416d356fffc94b8b18fe65039929 by Miss Islington (bot) in branch '3.9':
bpo-20281, bpo-29964: update datetime docs to refer %z and %Z to a pre-existing footnote (GH-30354)
Date User Action Args
2022-01-15 09:27:37iritkatrielsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-01-15 00:00:00miss-islingtonsetmessages: + msg410610
2022-01-14 23:59:35miss-islingtonsetmessages: + msg410608
2022-01-14 22:49:27miss-islingtonsetpull_requests: + pull_request28810
2022-01-14 22:49:23brett.cannonsetnosy: + brett.cannon
messages: + msg410604
2022-01-14 22:49:22miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request28808
2022-01-03 11:32:08hugovksetkeywords: + patch
nosy: + hugovk

pull_requests: + pull_request28567
stage: needs patch -> patch review
2021-11-30 12:05:41iritkatrielsetmessages: + msg407367
2021-11-28 13:17:44iritkatrielsettype: behavior -> enhancement
title: time.strftime %z format specifier is the same as %Z -> [doc] time.strftime %z format specifier is the same as %Z
components: + Library (Lib)

keywords: + easy
nosy: + iritkatriel
versions: + Python 3.11, - Python 3.3, Python 3.4
messages: + msg407206
2015-06-26 20:25:44r.david.murraysetmessages: + msg245865
2015-06-26 20:14:06dendorysetnosy: + dendory
messages: + msg245864
2015-06-26 19:18:28r.david.murraylinkissue24517 superseder
2014-01-16 20:41:26r.david.murraysetmessages: + msg208310
versions: + Python 3.3
2014-01-16 20:39:15Mike.Owenssetmessages: + msg208309
2014-01-16 20:36:08r.david.murraysetmessages: + msg208308
2014-01-16 19:29:50SilentGhostsetnosy: + SilentGhost
messages: + msg208301
2014-01-16 19:25:59Mike.Owenssetmessages: + msg208300
2014-01-16 19:14:18Mike.Owenssetmessages: + msg208299
2014-01-16 19:06:21r.david.murraysetassignee: docs@python
components: + Documentation, - Library (Lib)
versions: + Python 3.4, - Python 3.3
nosy: + docs@python, r.david.murray

messages: + msg208298
stage: needs patch
2014-01-16 18:39:50Mike.Owenssetmessages: + msg208296
2014-01-16 18:35:42Mike.Owenscreate