检索日期,7 小时关闭时间? [英] Retrieved date, time off by 7 hours?

查看:32
本文介绍了检索日期,7 小时关闭时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法显示正确的日期,实际上只是时间.

I am having trouble displaying the correct date, well actually its only the time.

在数据库中,日期以这种形式存储:'2012-09-28 23:30:00'(实际日期时间相差 7 小时)

In the db the date is stored in this form: '2012-09-28 23:30:00' (off by 7 hours of actual date time)

这是事件日期的值.

当我使用这个脚本(对于 drupal)检索它时:$ttdate = $obj->field_date_test_value;$nttdate = strtotime($ttdate);$okdate = format_date($nttdate, $type = 'medium');打印 $okdate;

When I retrieve it using this script(for drupal): $ttdate = $obj->field_date_test_value; $nttdate = strtotime($ttdate); $okdate = format_date($nttdate, $type = 'medium'); print $okdate;

...它工作正常,但时间差了 7 小时.因此,不是显示Fri, 9/28/2012 - 4:30pm",而是显示Fri, 9/28/2012 - 11:30pm".

...it works fine but the time is off by 7 hours. So instead of showing 'Fri, 9/28/2012 - 4:30pm' it shows 'Fri, 9/28/2012 - 11:30pm'.

请注意,在事件页面上,drupal 会检索到正确的时间...

Note that on the event's page, drupal retrieves the correct time...

我做了一些研究,我认为这与时区有关?但是我将时区设置为洛杉矶,所以我不太确定发生了什么.也许是我的脚本?

I did some research and I figured it has to do with the timezone? But I have the timezone set to Los Angeles so I am not quite sure what is going on. Maybe its my script?

推荐答案

我假设您使用的是 Date 模块.

I assume that you use the Date module.

这可能是因为 Date 模块以 UTC 格式保存日期并在渲染时更改输出(使用 format_date(),我认为).由于您没有在自己的代码中格式化日期,因此即使事件页面显示了正确的日期,您也会看到原始 UTC 时间(即 PDT + 7 小时).

This is probably because the Date module saves the date in UTC and alters the output on rendering (using format_date(), I think). Since you do not format the date in your own code, you see the raw UTC time (which is PDT + 7 hours) even though the correct date is displayed by the event page.

本页底部 解释了 Date 模块中时区的处理方式.我的猜测是第一种或第三种情况与您的情况相关.

The bottom of this page explains how timezones are handled in the Date module. My guess is that either the first or third scenario is relevant in your case.

这篇关于检索日期,7 小时关闭时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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