phpubuntutimezone

Using the system's time zone settings in PHP


So I have a web app written in PHP that will run on different Ubuntu servers around the world. Some of the servers will be configured to run on local time, some will run on UTC, it depends on the customer.

While I can edit the php.ini-file and set date.timezone, manually enter such data is bound to get wrong one day.

How can I get PHP to use the time zone already defined in the system (tzdata)?

Or, in other words: How can I extract (the long) time zone name from the system in PHP to use in date_default_timezone_set()?


Solution

  • If you have timezone set you could use: http://php.net/manual/en/function.date-default-timezone-get.php

    Or http://php.net/manual/en/function.timezone-name-from-abbr.php