[英]Weird Time Issue in Python
Problem with using times in Python. 在Python中使用时间的问题。
Terminal > Python 终端> Python
>>> calendar.timegm(datetime.datetime.now().utctimetuple())
1258449380
This time indicates GMT: Tue, 17 Nov 2009 09:16:20 GMT
这次表示
GMT: Tue, 17 Nov 2009 09:16:20 GMT
Eclipse via Django Server 通过Django服务器的Eclipse
>>> calendar.timegm(datetime.datetime.now().utctimetuple())
1258427784
This time indicates GMT: Tue, 17 Nov 2009 03:16:24 GMT
这次表示
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. 我当前的时区是格林尼治标准时间(GMT),时间是9点16分,这表示终端是正确的,但是Eclipse / Django的时间是6小时。 I'm so confused.
我很混乱。 I thought they'd both be using the same version of Python?
我以为他们都将使用相同版本的Python? As far as I'm aware I only have 2.6.2 installed.
据我所知,我只安装了2.6.2。
Django is set to Chicago time. Django设置为芝加哥时间。 You to change it, edit (or add in) TIME_ZONE flag in settings.py.
您可以更改它,在settings.py中编辑(或添加)TIME_ZONE标志。
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/ 如果您在Windows上运行,那么如果您未将Django设置为本地区域,则Django可能会使其混乱-http: //docs.djangoproject.com/en/dev/ref/settings/
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. 您可以通过运行
python -c "import sys; print sys.path
并检查输出以查看它们是否相同来检查它是否与python版本相同。
Otherwise - it might be related to your TZ environment variable, or other timezone setting. 否则-它可能与您的TZ环境变量或其他时区设置有关。 Perhaps Django sets a global timezone somewhere in the environment.
也许Django在环境中的某个地方设置了全球时区。 .
。 To check this you could try using
utcnow()
instead of now().utctimetuple
. 要检查这一点,您可以尝试使用
utcnow()
而不是now().utctimetuple
。 If these are the same then it is that each environment thinks it's in a different timezone. 如果这些相同,则是每个环境都认为它处于不同的时区。
Bordering on silly, are these two running on the same machine? 傻乎乎的是,这两个在同一台机器上运行吗? If not, are both machines using NTP to synchronise time?
如果不是,是否两台计算机都使用NTP同步时间?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.