PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

date_format> <date_default_timezone_get
Last updated: Fri, 05 Sep 2008

view this page in

date_default_timezone_set

(PHP 5 >= 5.1.0)

date_default_timezone_set スクリプト中の日付/時刻関数で使用されるデフォルトタイムゾーンを設定する

説明

bool date_default_timezone_set ( string $timezone_identifier )

date_default_timezone_set() は、日付/時刻関数で 使用されるデフォルトタイムゾーンを設定します。

注意: PHP 5.1.0 以降(日付/時刻 関数が書き直されてから)、タイムゾーンを 正しく設定せずに日付/時刻関数をコールすると E_NOTICE が発生し、またシステムの設定や TZ 環境変数を 使用すると E_STRICT が発生するようになりました。

スクリプト内でこの関数を使用してデフォルトタイムゾーンを設定するかわりに、 INI 設定 date.timezone でデフォルトタイムゾーンを設定することもできます。

パラメータ

timezone_identifier

タイムゾーン ID 。例えば UTCEurope/Lisbon など。有効な ID の一覧は サポートされるタイムゾーンのリスト にあります。

返り値

この関数は、timezone_identifier が 無効なものである場合に FALSE、それ以外の場合に TRUE を返します。

変更履歴

バージョン 説明
5.1.2 timezone_identifier パラメータの内容を 検証するようになりました。



date_format> <date_default_timezone_get
Last updated: Fri, 05 Sep 2008
 
add a note add a note User Contributed Notes
date_default_timezone_set
Rob Kaper
15-Jul-2008 05: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 );

?>
php_manual at lk2 dot de
13-Aug-2007 05: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
PeerGoal.com
12-Feb-2007 09: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");
davidn at datalinktech dot com dot au
22-Dec-2006 10: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.

date_format> <date_default_timezone_get
Last updated: Fri, 05 Sep 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites