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

佐手、 提交于 2019-12-12 18:13:38

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/1550432/how-to-use-zend-date-to-print-a-time-in-a-specific-timezone

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