Hi Folks! This is a short article about a common warning we can get when using php without be careful with the settings. It's quite importante in your application to determine the time zone you are in. If you don't do so, you can get warnings such the one below:
Warning: date_default_timezone_get(): 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.
To sort it out just add into your application the function date_default_timezone_set('value');
As value you can use any of the supported timezones by PHP, they can be found here.
Enjoy!
References:
http://php.net/manual/en/function.date-default-timezone-set.php
http://php.net/manual/en/timezones.php
Showing posts with label Timezone. Show all posts
Showing posts with label Timezone. Show all posts
Wednesday, January 9, 2013
Monday, September 24, 2012
Instalando o Composer: Erro timezone
Bem, instalando o Composer em meu computador me deparei com a seguinte mensagem:
Some settings on your machine may cause stability issues with Composer.
If you encounter issues, try to change the following:
The date.timezone setting should be provided.
Add the following to the end of your `php.ini`:
; UTC here is an example, use your own timezone, see http://www.php.net/manual/en/timezones.php
date.timezone = UTC
Downloading...
Composer successfully installed to: /home/user/composer.phar
Use it: php composer.phar
Para resolver acesse o php.ini do cli como abaixo:
shell> nano /etc/php5/cli/php.ini
E procure a linha date.timezone adicionando algum favor:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = 'America/Sao_Paulo'
Pronto, problema resolvido. =)
Tuesday, July 17, 2012
[OFF-TOPIC] Creating a List of Timezones with PHP
Hey guys,
Below you can find how to create a list of timezones with PHP using the native object DateTimeZone. Enjoy!
To use it just write in your code:
Below you can find how to create a list of timezones with PHP using the native object DateTimeZone. Enjoy!
<?php
class TimeZone
{
static $regions = array(
'Africa' => \DateTimeZone::AFRICA,
'America' => \DateTimeZone::AMERICA,
'Antarctica' => \DateTimeZone::ANTARCTICA,
'Asia' => \DateTimeZone::ASIA,
'Atlantic' => \DateTimeZone::ATLANTIC,
'Europe' => \DateTimeZone::EUROPE,
'Indian' => \DateTimeZone::INDIAN,
'Pacific' => \DateTimeZone::PACIFIC,
);
/**
*
* @return array List of locations
*/
static public function getLocations()
{
foreach (self::$regions as $name => $mask) {
$tzlist = \DateTimeZone::listIdentifiers($mask);
foreach ($tzlist as $tz) {
$locations[$name][$tz] = substr($tz, strrpos($tz, '/') + 1);
}
}
return $locations;
}
}
?/>
To use it just write in your code:
<?php
$locations = TimeZone::getLocations();
?>
Subscribe to:
Posts (Atom)