如何在Google App Engine中获得当前的英国时间 [英] How to get current UK time in Google App Engine

查看:185
本文介绍了如何在Google App Engine中获得当前的英国时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的机器上的python下,我可以运行 datetime.now()来获取当地时间。如果我检查 time.daylight 标志,它设置为 1 ,因为我们目前在7月(因此是夏令时)。

Under python on my machine I can run datetime.now() to get the local time. If I inspect time.daylight flag it is set to 1 because we are currently in July (hence daylight saving).

但是,如果我在Google App Engine(包括开发人员服务器)上运行 datetime.now()记录夏令时(英国夏季时间),并返回错误的时间(13:47而不是14:47)。如果我在GAE中检查 time.daylight ,则设置为 0

But if I run datetime.now() on Google App Engine (including the dev server) it doesn't account for daylight saving (british summer time) and returns the wrong time (13:47 instead of 14:47). If I inspect time.daylight in GAE it is set to 0.

如何获得正确的本地时间?我需要更改我的应用程序的时区吗?

How can I get the correct local time? Do I need to change the timezone on my app?

推荐答案

Google App Engine的时区始终设置为UTC。

Google App Engine's "time zone" is always set to UTC.

您可以使用像pytz这样的库来调整到本地或所需的时区。

You can adjust to your local or desired time zone using a library like pytz.

查看Google代码上的以下项目,了解App Engine优化版本的pytz。

Check out the following project on Google Code for an App Engine optimized version of pytz.

Google代码 - gae-pytz

这篇关于如何在Google App Engine中获得当前的英国时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆