检索日期,休息7小时? [英] Retrieved date, time off by 7 hours?

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

问题描述



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



这是事件日期的值。



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



...它工作正常,但时间关闭了7个小时。所以,而不是显示'星期五,9/28/2012 - 下午4:30,它显示'Fri,9/28/2012 - 11:30 pm'。



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



我做了一些研究,我认为它与时区有关?但是我有时区设在洛杉矶,所以我不太清楚发生了什么。可能是我的脚本?

解决方案

我假设你使用Date模块。



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



此页面的底部解释了如何在Date模块中处理时区。我的猜测是,第一种情况或第三种情况与您的情况相关。


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

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

That is the value for a date of an event.

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;

...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'.

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?

解决方案

I assume that you use the Date module.

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.

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天全站免登陆