time.strftime Timezone issue

Allen Unueco allen at premierweb.com
Sun Jun 13 06:08:23 CEST 2004


Tim,

As it turns out it was my mistake for using gmtime() not localtime(). 
Not really any point is formating the timezone when you are asking for 
the time in UTC. But it is a little strange why it should change, if 
anything I would assume it would change to UTC.

Here is the output from my Debian (woody) box

Python 2.2.1 (#1, Feb 28 2004, 00:52:10)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import time
 >>> time.daylight
1
 >>> time.strftime("%Z")
'EDT'
 >>> time.strftime("%Z", time.localtime())
'EDT'
 >>> time.strftime("%Z", time.gmtime())
'EST'

It seems to work fine on my OSX system, although I'm confused by 
time.daylight being set to '1' when it's NZST right now, down here.

Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import time
 >>> time.daylight
1
 >>> time.strftime("%Z")
'NZST'
 >>> time.strftime("%Z", time.gmtime())
'NZST'
 >>> time.strftime("%Z", time.localtime())
'NZST'

Sorry for the incomplete original post,
-allen

Tim Peters wrote:

> [Allen Unueco]
> 
>>I feel that the '%Z' format specifier from strftime() returns the wrong
>>value when daylight savings is in effect.
>>
>>Today the following is always true: time.strftime('%Z') == time.tzname[0]
>>
>>Shouldn't it be: time.strftime('%Z') == time.tzname[time.daylight]
> 
> 
> Please give a concrete example, including Python version and OS.  Platform C
> bugs in time functions are common as mud.  Here's my concrete example,
> Python 2.3.4 on WinXP running in US Eastern:
> 
> C:\Code>\python23\python.exe
> Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
> 
>>>>import time
>>>>time.tzname
> 
> ('Eastern Standard Time', 'Eastern Daylight Time')
> 
>>>>time.daylight
> 
> 1
> 
>>>>time.strftime("%Z")
> 
> 'Eastern Daylight Time'
> 
> 
> Here's another, Python 2.2.2 on a Red Hat box:
> 
> -bash-2.05b$ python
> Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
> [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> 
>>>>import time
>>>>time.tzname
> 
> ('EST', 'EDT')
> 
>>>>time.daylight
> 
> 1
> 
>>>>time.strftime("%Z")
> 
> 'EDT'
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 



More information about the Python-list mailing list