If you have problems with errors, why the default is not set use this on the top of the script:
<?php
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
@date_default_timezone_set(@date_default_timezone_get());
?>
date_default_timezone_set
(PHP 5 >= 5.1.0)
date_default_timezone_set — Configura a timezone padrão a ser utilizada por todas as funções de data e hora em um script
Descrição
date_default_timezone_set() configura a timezone padrão a ser utilizada por todas as funções de data e hora em um script
Nota: Desde o PHP5.1.0 (quando as funções de data e tempo foram reescritas), toda chamada a esse tipo de função irá gerar um E_NOTICE se a timezone não é válida, e/ou uma mensagem E_STRICT se estiver utilizando as configurações do sistema ou a variável de ambiente TZ.
Ao invés de utilizar essa função para setar a timezone padrão no seu script, você pode também utilizar a configuração INI date.timezone para configurar a timezone padrão.
Parâmetros
- timezone_identifier
-
O identificador da timezone, como UTC ou Europe/Lisbon. A lista de identificadores válidos está disponível em List of Supported Timezones.
Valor Retornado
A função retorna FALSE se o timezone_identifier não é válido, ou TRUE caso contrário.
Histórico
| Versão | Descrição |
|---|---|
| 5.1.2 | A função passou a validar o parâmetro timezone_identifier . |
date_default_timezone_set
28-Sep-2008 07:34
15-Jul-2008 10:46
If you want users to choose their own timezones, here's some code that gets all available timezones but only uses one city for each possible value:
<?php
$timezones = DateTimeZone::listAbbreviations();
$cities = array();
foreach( $timezones as $key => $zones )
{
foreach( $zones as $id => $zone )
{
/**
* Only get timezones explicitely not part of "Others".
* @see http://www.php.net/manual/en/timezones.others.php
*/
if ( preg_match( '/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\//', $zone['timezone_id'] ) )
$cities[$zone['timezone_id']][] = $key;
}
}
// For each city, have a comma separated list of all possible timezones for that city.
foreach( $cities as $key => $value )
$cities[$key] = join( ', ', $value);
// Only keep one city (the first and also most important) for each set of possibilities.
$cities = array_unique( $cities );
// Sort by area/city name.
ksort( $cities );
?>
12-Aug-2007 10:37
@davidn at datalinktech dot com dot au
set_default_timezone() has no effect at all on how apache logs are timestamped (at least for me)
[red. that's untrue if you set the TZ env var... that will affect Apache as well - Derick]
It is however true, that all dates and times that php formats that are _not_ timestamps will be in that timezone.
Timestamps are always GMT
12-Feb-2007 01:21
The problem:
date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable 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. We selected 'America/Los_Angeles' for 'PST/-8.0/no DST' instead
Of course this is a problem that recently surfaced since PHP5. Quick fix is to set your time zone, add this line to your php code:
date_default_timezone_set("America/Los_Angeles");
22-Dec-2006 02:27
Note that there may be some unexpected side-effects that result from using either set_default_timezone() or the putenv("TZ=...") workalike for earlier PHP versions. ANY date formatted and output either by PHP or its apache host process will be unconditionally expressed in that timezone.
[red. That is only true for the putenv() hack - Derick]
This does indeed include the web server's logs and other output files and reports which by default usually do not include any indication of timezone. This has a further side-effect on log processing and analysis, obviously.
