Search code examples
zend-frameworkzend-date

How to use Zend_Date to print a time in a specific timezone


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.


Solution

  • 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