Handling date.timezone setting in an application

Hi,

There is one place in my application that I am using date() function. On servers where “date.timezone” is not set in the php.ini file, this function gives the following warning:

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.

Now, since this application will be distributed and I can’t control all servers, I am trying to find the best way to handle this.

Here is the options I could find:

  1. Suppress the warning by “@date()”.

  2. Check if “date.timezone” value is not set in php.ini and suppress the warning accordingly:

$timezone = ini_get('date.timezone');
if (empty($timezone)) {
echo @date('Y');
} else {
echo date('Y');
}
  1. Check if “date.timezone” value is not set in php.ini and set a default timezone, which is not I want because the application will be used all around the world:
$timezone = ini_get('date.timezone');
if (empty($timezone)) {
date_default_timezone_set('Europe/London');
}

echo date('Y');

Please let me know if you have any ideas about this. Thanks.

I’d say go for option 3, what timezone is set to be used is down to whoever maintains a given server. You could have a note to whoever is installing the app just above or just below in a comment asking them to leave it set for GMT/UTC