如何使用Zend_Date打印特定时区的时间 [英] How to use Zend_Date to print a time in a specific timezone

查看:100
本文介绍了如何使用Zend_Date打印特定时区的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我使用Zend_Date.我设置了date_default_timezone_set('UTC'),因为在内部和数据库中,我只想拥有UTC时间.

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.

对于用户,我想在当地时间显示它.最简单的方法是什么?假设我在$ user-> timezone和$ date的视图中,其中$ timezone是'Europe/Helsinki',而$ date是Zend_Date.

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.

推荐答案

应该在手册中对其进行详细记录,因为这是一个非常常见的用例.幸运的是,它既简单又方便:

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

这篇关于如何使用Zend_Date打印特定时区的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆