5

I created a node type with a date field (from the date module). I list nodes of this type in a view. The problem I have is that the date values being shown by the view are in UTC (ie as they are stored in the db) not in the user's local timezone. I have tried the following to no avail:

1) Unchecked "Administration » Configuration » Regional and language » Users may set their own time zone". I then logged out and cleared the cache.

2) Verified that if I view the node outside of the view (ex: going to http://mysite.local/node/123), the time appears in the proper timezone. The proper dates are also shown when editing the node.

3) Tried to format the date using this code:

format_date($date, 'custom', 'D d/m/Y - g:ia', date_default_timezone_get())

$date is a timestamp and date_default_timezone_get() returns the proper timezone.

4) Tried this with the date_views modules enabled and disabled.

For some reason the view pulls the date field value straight from the db without converting it to the proper timezone. Unfortunately, I don't know how to either 1) tell views how to convert it properly, or 2) convert it manually in a template.

Note: I refuse to hard-code my timezone into my template. This is a terrible option I've seen when searching for an answer to this.

2 Answers 2

0

You can use Global PHP filed to convert the date in user's proper timezone using code. Your date field value will be the input here. If it works then use this field instead and set the original date field to 'exclude from display' in your view.

0

I just ran into this problem recently and saw this post without a real solution. For me editing the Date field in the content type and setting the "Time zone handling" to "No time zone conversion" than re-saving the nodes solved the problem.

Not the answer you're looking for? Browse other questions tagged or ask your own question.