Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > datetime module and timezone

Reply
Thread Tools

datetime module and timezone

 
 
Olive
Guest
Posts: n/a
 
      02-10-2012
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
 
Reply With Quote
 
 
 
 
John Gordon
Guest
Posts: n/a
 
      02-10-2012
In <(E-Mail Removed)> Olive <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      02-10-2012
On Fri, Feb 10, 2012 at 1:25 PM, Olive <(E-Mail Removed)> 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
 
Reply With Quote
 
Bob Martin
Guest
Posts: n/a
 
      02-11-2012
in 671891 20120210 212545 Olive <(E-Mail Removed)> 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.
 
Reply With Quote
 
all mail refused
Guest
Posts: n/a
 
      02-11-2012
On 2012-02-11, Bob Martin <(E-Mail Removed)> wrote:
> in 671891 20120210 212545 Olive <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert stored mysql DateTime of UTC datetime stamp into another timezone Justin Voelker Javascript 2 12-02-2008 08:23 PM
TimeZone calculation on Windows Vista with DateTime::TimeZone Ami Perl Misc 5 09-24-2007 07:27 AM
mx.DateTime to datetime.datetime mp Python 1 07-28-2006 10:57 PM
datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Christos TZOTZIOY Georgiou Python 3 09-13-2003 10:44 AM
RE: datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Tim Peters Python 0 09-09-2003 12:57 AM



Advertisments