datetime module and timezone

Discussion in 'Python' started by Olive, Feb 10, 2012.

  1. Olive

    Olive Guest

    In the datetime module, it has support for a notion of timezone but is
    it possible to use one of the available timezone (I am on Linux). Linux
    has a notion of timezone (in my distribution, they are stored
    in /usr/share/zoneinfo). I would like to be able 1) to know the current
    timezone and 2) to be able to use the timezone available on the system.
    How can I do that?

    Olive
     
    Olive, Feb 10, 2012
    #1
    1. Advertising

  2. Olive

    John Gordon Guest

    In <> Olive <> writes:

    > In the datetime module, it has support for a notion of timezone but is
    > it possible to use one of the available timezone (I am on Linux). Linux
    > has a notion of timezone (in my distribution, they are stored
    > in /usr/share/zoneinfo). I would like to be able 1) to know the current
    > timezone and 2) to be able to use the timezone available on the system.
    > How can I do that?


    I believe the current user's timezone is stored in the TZ environment
    variable.

    I don't understand your second question. Are you asking for a list of
    of all the possible timezone choices?

    --
    John Gordon A is for Amy, who fell down the stairs
    B is for Basil, assaulted by bears
    -- Edward Gorey, "The Gashlycrumb Tinies"
     
    John Gordon, Feb 10, 2012
    #2
    1. Advertising

  3. Olive

    Chris Rebert Guest

    On Fri, Feb 10, 2012 at 1:25 PM, Olive <> wrote:
    > In the datetime module, it has support for a notion of timezone but is
    > it possible to use one of the available timezone (I am on Linux). Linux
    > has a notion of timezone (in my distribution, they are stored
    > in /usr/share/zoneinfo). I would like to be able 1) to know the current
    > timezone


    time.tzname gives the zone names (plural due to DST); time.timezone
    and time.altzone gives their UTC offsets.

    > and 2) to be able to use the timezone available on the system.


    You can use the name to look it up in pytz (http://pypi.python.org/pypi/pytz/ ).
    And python-dateutil (http://labix.org/python-dateutil ) can apparently
    parse zoneinfo files, if that's what you mean.

    Cheers,
    Chris
     
    Chris Rebert, Feb 10, 2012
    #3
  4. Olive

    Bob Martin Guest

    in 671891 20120210 212545 Olive <> wrote:
    >In the datetime module, it has support for a notion of timezone but is
    >it possible to use one of the available timezone (I am on Linux). Linux
    >has a notion of timezone (in my distribution, they are stored
    >in /usr/share/zoneinfo). I would like to be able 1) to know the current
    >timezone and 2) to be able to use the timezone available on the system.
    >How can I do that?


    For 1) just type "date" on the command line.
     
    Bob Martin, Feb 11, 2012
    #4
  5. On 2012-02-11, Bob Martin <> wrote:
    > in 671891 20120210 212545 Olive <> wrote:
    >>In the datetime module, it has support for a notion of timezone but is
    >>it possible to use one of the available timezone (I am on Linux). Linux
    >>has a notion of timezone (in my distribution, they are stored
    >>in /usr/share/zoneinfo). I would like to be able 1) to know the current
    >>timezone


    > For 1) just type "date" on the command line.


    But "date" gets it from somewhere else (otherwise infinite loop).
    If there's no environment variable it seems to use files like these.
    open("/usr/lib/locale/en_GB.utf8/LC_TIME", O_RDONLY) = 3
    ...
    open("/etc/localtime", O_RDONLY) = 3


    --
    Elvis Notargiacomo master AT barefaced DOT cheek
     
    all mail refused, Feb 11, 2012
    #5
    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. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    734
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    556
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    403
    John Machin
    Jul 28, 2006
  4. Ami
    Replies:
    5
    Views:
    298
  5. Justin Voelker
    Replies:
    2
    Views:
    274
    Dr J R Stockton
    Dec 2, 2008
Loading...

Share This Page