views:

77

answers:

3

Problem with using times in Python.

Terminal > Python

>>> calendar.timegm(datetime.datetime.now().utctimetuple())
1258449380

This time indicates GMT: Tue, 17 Nov 2009 09:16:20 GMT

Eclipse via Django Server

>>> calendar.timegm(datetime.datetime.now().utctimetuple())
1258427784

This time indicates GMT: Tue, 17 Nov 2009 03:16:24 GMT

My current timezone is infact GMT and the time is 16 minutes past 9, which means the Terminal is correct, however the Eclipse/Django one is 6 hours off. I'm so confused. I thought they'd both be using the same version of Python? As far as I'm aware I only have 2.6.2 installed.

A: 

Bordering on silly, are these two running on the same machine? If not, are both machines using NTP to synchronise time?

Vatine
+2  A: 

You can check if it's the same version of python by running python -c "import sys; print sys.path and inspecting the output to see if they are the same.

Otherwise - it might be related to your TZ environment variable, or other timezone setting. Perhaps Django sets a global timezone somewhere in the environment. . To check this you could try using utcnow() instead of now().utctimetuple. If these are the same then it is that each environment thinks it's in a different timezone.

thrope
+7  A: 

Django is set to Chicago time. You to change it, edit (or add in) TIME_ZONE flag in settings.py.

If you are running on Windows, then Django might mess things up if you don't set it to your local zone - http://docs.djangoproject.com/en/dev/ref/settings/

wisty
I vaguely remember changing that variable in my last Django project. Damn. Thanks a lot!
day_trader
I think it's actually set to Lawrence, Kansas time, which is in the same time zone as Chicago.
S.Lott