googleappenginesdk:系统时间不同于计算机tim

2024-05-14 21:24:37 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: datetime系统时间now小时计算机系统时差googleappengine
1条回答
网友
1楼 · 发布于 2024-05-14 21:24:37

请参见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,以及如何进行特殊处理的示例。在

相关问题 更多 >

    热门问题