datetime module and timezone

O

Olive

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
 
J

John Gordon

In said:
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?
 
C

Chris Rebert

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
 
B

Bob Martin

in 671891 20120210 212545 Olive said:
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.
 
A

all mail refused

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top