Work with dates and time zones, with Zend_Date

I have an application that uses Zend_Date to display dates. Zend_Date instances are created using datetime data from MySQL, user input, and current date.

I would like my users to be able to specify their time zone and all the dates that will be displayed in their local time.

My code currently works as follows:

$date = '2009-01-01 10:30:00'; $date = new Zend_Date($date, Zend_Date::ISO_8601); echo $date->get(Zend_Date::TIME_MEDIUM); //10:30:00 $date->setTimezone('Australia/ACT'); echo $date->get(Zend_Date::TIME_MEDIUM); //21:30:00 

This works, but a setTimezone call is required for each date. Is there an easier way to manage time zones?

I also consider using SET time_zone with MySQL to return adjusted data from MySQL. Then I will only need to configure the dates created in PHP scripts for time zones.

I would like to hear the best way to handle this if someone has experience.

thanks

+6
date php zend-framework
source share
2 answers

I think setting the PHP time zone should set a default value for all subsequent instances of Zend_Date. For example:

 date_default_timezone_set('Europe/Vienna'); 

From the Zend_Date section of the Zend Framework Reference Guide :

In PHP, we can configure all the date and time related functions to work for a specific user by setting the default time zone in accordance with user expectations. When creating Zend_Date instances, their time zone will automatically become the current default time zone!

+7
source share

I think you could use Zend_Locale, read some docs about this, making sure you can make it work. On the other hand, if you use Zend_Cache and Zend_Locale / Zend_Date, this will help to improve the speed a bit. There are examples of using the zend environment in documents.

+1
source share

All Articles