Time.strftime () wrong timezone format

I stumbled upon an issue with Python 2.7.8 on Windows 8.1. I was trying to pull the UTC offset for the local timezone of the computer using time.strftime('%z')

, I expected to get the UTC offset ( -0700

), I got the full timezone name ( ) instead Pacific Daylight Time

. I re-ran strftime()

in another Python interpreter (on a RaspberryPi running Python 2.7.3) and got the expected UTC offset.

Code running on Windows machine with output

>>> import time
>>> time.strftime('%z')
'Pacific Daylight Time'

      

The code running on RaspberryPi was identical except for the exit (RaspberryPi localization time is set to UTC)

>>> import time
>>> time.strftime('%z')
'+0000'

      

I know most Python timing methods are wrappers for system calls, this is the case where the underlying system call fails as described for the strftime formatting character implementation to change from 2.7.3 and 2.7.8 (although the docs for 2.7.8 say lowercase z should return UTC offset)?

For more information about the time zone and language information of a Windows computer:

>>> import locale; locale.getlocale(); locale.getdefaultlocale()
(None, None)
('en_US', 'cp1252')
>>> time.tzname
('Pacific Standard Time', 'Pacific Daylight Time')

      

+3
python python-2.7 datetime


source to share


No one has answered this question yet

See similar questions:

40
Getting the UTC offset of a computer in Python
13
Python: strftime () UTC Offset Doesn't work as expected on Windows

or similar:

1350
Where can I find documentation on formatting dates in JavaScript?
1311
String formatting:% vs. .format
628
How do I print the date in regular format?
fourteen
Python: strftime, gmtime does not respect timezone
8
Python logging module emits incorrect timezone information
4
Timezone support in ColdFusion?
3
Get system time with timezone in Django, bypassing default timezone
3
Is it possible to get the timezone in Python given the UTC timestamp and UTC offset?
1
Find daylight saving time status of naive time and time given by time zone
1
Weird python time.strftime () timezone display



All Articles
Loading...
X
Show
Funny
Dev
Pics