RE: time.strftime Timezone issue

Discussion in 'Python' started by Tim Peters, Jun 13, 2004.

  1. Tim Peters

    Tim Peters Guest

    [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'
    >>>
     
    Tim Peters, Jun 13, 2004
    #1
    1. Advertising

  2. Tim Peters

    Allen Unueco Guest

    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'
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
     
    Allen Unueco, Jun 13, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Allen Unueco

    time.strftime Timezone issue

    Allen Unueco, Jun 13, 2004, in forum: Python
    Replies:
    1
    Views:
    364
    Allen Unueco
    Jun 13, 2004
  2. Tim Peters

    RE: time.strftime Timezone issue

    Tim Peters, Jun 13, 2004, in forum: Python
    Replies:
    0
    Views:
    682
    Tim Peters
    Jun 13, 2004
  3. asaf
    Replies:
    3
    Views:
    6,210
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Sep 11, 2006
  4. axrock
    Replies:
    8
    Views:
    986
    Roedy Green
    Mar 25, 2009
  5. David Joseph Bonnici
    Replies:
    1
    Views:
    227
    Gunnar Hjalmarsson
    May 15, 2005
Loading...

Share This Page