gpt4 book ai didi

python - 谷歌应用引擎 SDK : System time different from the computer time

转载 作者:行者123 更新时间:2023-11-28 22:00:58 26 4
gpt4 key购买 nike

在 Google App Engine 中,我使用 nowTime = datetime.datetime.now() 获取系统时间。但是,我发现它与计算机系统时间不同。比如nowTime2012-12-20 14:44:30.910192,但是我的电脑系统时间是2012-12-20 22:44 >。有八小时的时差。是因为时区吗? Google App Engine SDK 从哪里获得时间?谢谢。

最佳答案

参见 http://timezones.appspot.com/ - GAE 时区将始终采用 UTC,这就是您看到 8 小时时差的原因。根据网站:

The runtime's TZ environment variable is set to UTC, and can't be changed. Timestamps returned by e.g. time.time() and datetime.datetime.now() will always be in UTC. Similarly, datetime properties in the datastore will always be stored and returned as UTC.

You can change the time zone of a datetime in memory with the astimezone() method. If datetime's tzinfo member isn't set, you'll first need to set it to a UTC tzinfo with the replace() method.

您还可以看到它记录在案 here ,以及如何进行特殊处理的示例。

关于python - 谷歌应用引擎 SDK : System time different from the computer time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13974667/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com