CodeIgniter Forums
Especific Time Zone by user - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Especific Time Zone by user (/showthread.php?tid=1381)



Especific Time Zone by user - rmiguel - 03-05-2015

Hello,

Im trying to set an specific time zone by user. The point is that the specific time_zone is set in a controller

PHP Code:
ini_set('date.timezone''America/Santo_Domingo'); 

Even date_default_timezone_set is not working

PHP Code:
date_default_timezone_set('America/Santo_Domingo'); 


If time zone is set in the root index.php file of whole project, everything works fine

Thanks in advance,
Ruben


RE: Especific Time Zone by user - mwhitney - 03-05-2015

Usually, the best thing to do for something like this is to set the server's timezone in the index.php with date_default_timezone_set() (preferably to something like UTC, rather than the local time of wherever it happens to be hosted or you happen to be) and store any date/time data using that timezone. Then you can convert any times you've stored in the database to the user's timezone when you display them, using PHP's DateTime and DateTimeZone classes.

http://php.net/manual/en/datetime.settimezone.php