Serious Problem with Timezone

T

T-u-N-i-X

Hey There,

I'm a django developer and working on a project right now.. Last week
I just discovered a new problem in Python.. Here's what I do..

[01:00] (tunix@penguix ~)$ date
Sal May 20 01:00:10 EEST 2008
[01:00] (tunix@penguix ~)$ python
Python 2.5.2 (r252:60911, Feb 23 2008, 21:20:32)
[GCC 4.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
from datetime import datetime
datetime.now() datetime.datetime(2008, 5, 20, 1, 0, 21, 131804)
import os
os.environ["TZ"] = "Europe/Istanbul"
datetime.now() datetime.datetime(2008, 5, 19, 22, 0, 38, 578438)

It's 01:00 in Istanbul now and Python shows 22:00 on 19th of May if I
set the TZ environment variable.. Django sets that variable
automatically so I'm having problems with scheduled posts..

I controlled my system's BIOS time.. It was wrong before, so I just
corrected it.. I set the time to UTC on Linux.. What else can I do ?
 
J

Jason Scheirer

Hey There,

I'm a django developer and working on a project right now.. Last week
I just discovered a new problem in Python.. Here's what I do..

[01:00] (tunix@penguix ~)$ date
Sal May 20 01:00:10 EEST 2008
[01:00] (tunix@penguix ~)$ python
Python 2.5.2 (r252:60911, Feb 23 2008, 21:20:32)
[GCC 4.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>> from datetime import datetime
datetime.datetime(2008, 5, 20, 1, 0, 21, 131804)>>> import os
os.environ["TZ"] = "Europe/Istanbul"
datetime.now()

datetime.datetime(2008, 5, 19, 22, 0, 38, 578438)



It's 01:00 in Istanbul now and Python shows 22:00 on 19th of May if I
set the TZ environment variable.. Django sets that variable
automatically so I'm having problems with scheduled posts..

I controlled my system's BIOS time.. It was wrong before, so I just
corrected it.. I set the time to UTC on Linux.. What else can I do ?

You may want to investigate the datetime.astimezone() method, as well
as getting comfortable with using tzinfo objects. Check out
http://pypi.python.org/pypi/pytz/ for a module that can give you the
tz objects you want. Also useful is datetime.utcnow()* and
datetime.replace(tzinfo=other_tzinfo), which will give you that same
time but not 'smartly' try to adjust the components in the datetime
object.

I've found datetime.utcnow() is a little temperamental (bad tzinfo is
assigned by default, making it impossible to do conversions) and you
still need to do datetime.utcnow().replace(tzinfo=utctz) to get it to
behave well.
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top