classification
Title: time.strftime('%z') didn't make +HHMM return in windows xp
Type: behavior Stage: resolved
Components: Documentation, Library (Lib), Unicode, Windows Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Aaron.Meurer, Václav Dvořák, civalin, docs@python, eryksun, ezio.melotti, kepkin, martin-t, paul.moore, r.david.murray, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords:

Created on 2013-12-17 22:38 by civalin, last changed 2021-02-26 17:29 by eryksun. This issue is now closed.

Messages (10)
msg206484 - (view) Author: Civa Lin (civalin) Date: 2013-12-17 22:38
On windows xp (Taiwanese) platform...

    c:\> py -c "import time; print(time.strftime('%z', time.localtime()))"

It will raise a UnicodeEncodeError in my system.

I think it's not a +HHMM format and has different behavior with document:
    http://docs.python.org/3/library/time.html#time.strftime
msg206488 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-12-17 23:41
As the documentation of the module says, we pass this call through to the underlying c library.  What does the Windows documentation say about %z?

A quick google turns up this hit, which seems to indicate it is a platform problem:

http://connect.microsoft.com/VisualStudio/feedback/details/797109/strftime-incorrect-multibyte-encoding-of-timezone-z
msg206489 - (view) Author: Civa Lin (civalin) Date: 2013-12-17 23:46
Oh! Thanks your info!
msg215853 - (view) Author: Aaron Meurer (Aaron.Meurer) Date: 2014-04-09 22:49
The docs could be much more clear about this in my opinion.
msg215976 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-04-12 16:31
Can you suggest how to improve the docs?
msg215977 - (view) Author: Aaron Meurer (Aaron.Meurer) Date: 2014-04-12 17:14
Nowhere at https://docs.python.org/3.5/library/time.html#time.strftime is it indicated that %z behaves differently on different platforms. What it *does* say is

%z	Time zone offset indicating a positive or negative time difference from UTC/GMT of the form +HHMM or -HHMM, where H represents decimal hour digits and M represents decimal minute digits [-23:59, +23:59].

I see now that this is mentioned in the footnote at the bottom of the page.

I would split that footnote into two notes. It's really about two things, %Z/%z compatibility, and the RFC. The RFC note should stay as it is in the footnote, but I would move the bits about %Z/%z compatibility much close to their entries in the table, as that is where people are going to look (I personally wouldn't even hide the information in a footnote, but that can be debated).
msg215978 - (view) Author: Aaron Meurer (Aaron.Meurer) Date: 2014-04-12 17:16
I also just noticed that the %z entry in the table wasn't added until the Python 3.3 docs, although it apparently works at least in OS X in Python 2.7 (I can't test Windows right now).  Was it supposed to be one of the "additional directives supported on certain platforms"?
msg222998 - (view) Author: Alexandr Nevskiy (kepkin) Date: 2014-07-14 06:20
The same odd behavior for Windows 7

C:\Python34\python.exe
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.strftime('%z', time.localtime(time.time()))
'Russian Standard Time'
>>> time.strftime('%Z', time.localtime(time.time()))
'Russian Standard Time'
msg229028 - (view) Author: Martin Taibr (martin-t) Date: 2014-10-10 20:01
Same behavior on Windows 8.1. Possible workaround:

>>> from datetime import datetime
>>> from dateutil import tz
>>> datetime.now(tz.tzlocal()).strftime('%z')
'+0200'
msg260435 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-02-18 07:08
%z works correctly in the new CRT that's used by 3.5:

    Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25)
    [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import time
    >>> time.strftime('%z', time.localtime(time.time()))
    '-0000'
    >>> time.strftime('%Z', time.localtime(time.time()))
    'Coordinated Universal Time'
History
Date User Action Args
2021-02-26 17:29:48eryksunsetstatus: open -> closed
resolution: out of date
stage: resolved
2016-02-18 07:08:14eryksunsetversions: + Python 2.7
nosy: + tim.golden, eryksun, paul.moore, docs@python, zach.ware, steve.dower

messages: + msg260435

assignee: docs@python
components: + Documentation
2016-02-18 00:18:27Václav Dvořáksetnosy: + Václav Dvořák
2014-10-10 20:01:25martin-tsetnosy: + martin-t
messages: + msg229028
2014-07-14 06:20:38kepkinsetnosy: + kepkin

messages: + msg222998
versions: + Python 3.4
2014-04-12 17:16:28Aaron.Meurersetmessages: + msg215978
2014-04-12 17:14:24Aaron.Meurersetmessages: + msg215977
2014-04-12 16:31:14r.david.murraysetmessages: + msg215976
2014-04-09 22:49:07Aaron.Meurersetnosy: + Aaron.Meurer
messages: + msg215853
2013-12-17 23:46:53civalinsetmessages: + msg206489
2013-12-17 23:41:25r.david.murraysetnosy: + r.david.murray
messages: + msg206488
2013-12-17 22:38:51civalincreate