views:

184

answers:

1

In my app I use Zend_Date. I have set date_default_timezone_set('UTC') because internally and in the database I only want to have UTC times.

For users I want to display it in their local time. What is the easiest way to do this? Let's say, I have in the view $user->timezone and $date, where $timezone is 'Europe/Helsinki' and $date is a Zend_Date.

+2  A: 

This should be better documented in the manual, as it's a pretty common use case. Fortunately it's nice and easy:

$date->setTimezone($user->timezone);

echo $date->get(Zend_Date::TIME_SHORT); //prints in user timezone
David Caunt
It will cause quite some codeclutter if I do this for every date I print in my view. Is there no short method like $date->getByTimezone(Zend_Date::TIME_SHORT, $user->timezone)?
Peter Smit
I would suggest writing a simple view helper for this :)
David Caunt