How do I correctly display time in Drupal using the Date module?
When creating a new Event on my Drupal site I set the date/time of the event to what I assume is local time. I expected the date/time in the system to be set to the value I saw on the add/edit form, but its not; it's set to UTC.
Event Start (add/edit form): 2012-12-20 1:00pm EST Event Start (database): 2012-12-20 6:00pm UTC
When I go to display this date/time using date() even after setting the default timezone to EST ("America/Toronto") the date/time is still showing 2012-12-20 6:00pm.
The values are being posted as they're displayed: 5:00pm goes to the server as 3 distinct values: 5, 00, PM. They're being stored in the database as UTC, but not matter what I try they're always displayed as UTC. I've tried format_date, date_default_timezone_set, setting the PHP timezone in the .htaccess file...no luck :s
Hate having to do it manually, but this works:
$tz = new DateTimeZone('America/Toronto'); $offset = $tz->getOffset(new DateTime($start_date)); $start_stamp = strtotime($start_date) + $offset;
If you have a date formatter (config page at /admin/config/regional/date-time), you can use the machine name to reuse it:
$date = new DateObject($timestamp); $value = date_format_date($date, 'my_date_string_format');