Retrieved date, time off by 7 hours?

我怕爱的太早我们不能终老 提交于 2019-12-14 02:40:36

问题


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?


回答1:


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.




回答2:


Try the following in mysql:

set time_zone = '-07:00';


来源:https://stackoverflow.com/questions/12433529/retrieved-date-time-off-by-7-hours

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!