473,287 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Serious Problem with Timezone

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 ?
Jun 27 '08 #1
1 1018
On May 19, 3:02*pm, T-u-N-i-X <alperka...@gmail.comwrote:
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 ?
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.
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason Kinkade | last post by:
I recently installed MySQL 4.0.18 on my slackware 9.1 machine (kernel 2.4.25) by compiling the source. It works fine, and all tests pass except one. The timezone test. Can someone tell me why...
0
by: Todd Bandrowsky | last post by:
I'm fixing a generic TimeZone class in C# for a server application. If I derive from TimeZone and implement a GetDaylightChanges method that returns the same data as Microsoft's TimeZone, and...
1
by: Raj Chudasama | last post by:
I have the following code for a clock in my gui. Everything works fine EXCEPT the following line when the TimeZone is changed in the windows. string tz = TimeZone.CurrentTimeZone.StandardName;...
13
by: Stuart Bishop | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi. I'm trying to determine the best way of saying 'The current time in UTC with no time zone information'. I'm currently using...
3
by: asanford | last post by:
I want to create a web service that allows the caller to pass a DateTime to the web service (that is, create a web method such as void MyWebMethod(DateTime dt).) However, I want to be able to...
2
by: Roshawn Dawson | last post by:
Hi, I have a datetime value that is already in GMT (UTC) time. What I would like to do is convert this value into Pacific Standard Time, but I also need to account for daylight savings time. ...
0
by: helloitsme | last post by:
Hello All! I know there already exists a thread with this topic by Mike! But my problem did not get solved with that.... I have a working code in VB6 that can set the selected timezone for the...
2
by: John Hanley | last post by:
I am getting some inconsistencies with mktime(). I allocate memory for my struct tm early in my program, and assign only *some* of the member variables. t->tm_sec=s; t->tm_min=m;...
2
by: =?Utf-8?B?Sm9ubnk=?= | last post by:
I have an ASP.NET 2.0 C# web application that is contacting an Exchange server using WEBDAV. It allows the users to look up appointments for a future date. The problem I have is determining the...
6
by: jehugaleahsa | last post by:
Hello: I would like it so that the time displayed was always for CDT/CDS. Potentially, the application can be run at locations in Mountain Time or Central Time. This is what I have now: //...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.