Freitag, 27. Februar 2009

Change timezone in PHP

Assuming your webserver isn't in the timezone, it is expected - bought a cheap server in a foreign country ;) - you have two, actually three, ways to solve this.

1. During runtime


This solution nessetiates the fewest permissions. Just execute
putenv("TZ=Europe/Vaduz");

in your PHP script and done. Drawback: you have to do for every execution.

2. Permanent


If you're allowed to modify the php.ini, probably in
/etc/php5/apache2/php.ini

and change the parameter
date.timezone = Europe/Vaduz

A full list of all timezones can be found here.

To avoid any troubles with time conversion and timezones, you should use the Unix time or the Greenwich time.

Keine Kommentare:

Kommentar veröffentlichen