(PHP 5 >= 5.1.0)
date_default_timezone_get — 取得一個腳本中所有日期時間函數所使用的默認時區
說明
string date_default_timezone_get ( void )本函數返回默認時區,使用如下“假定”的順序:
用 date_default_timezone_set() 函數設定的時區(如果設定了的話)
僅僅在 PHP 5.4.0 之前: TZ 環境變量(如果非空)
date.timezone 配置選項(如果設定了的話)
僅僅在 PHP 5.4.0 之前: 查詢操作系統主機 (如果操作系統支持并允許)。 This uses an algorithm that has to guess the timezone. This is by no means going to work correctly for every situation. A warning is shown when this stage is reached. Do not rely on it to be guessed correctly, and set date.timezone to the correct timezone instead.
如果以上選擇都不成功,date_default_timezone_get() 會則返回 UTC 的默認時區。
返回值
返回一個 string。
更新日志
版本 說明 5.4.0 不再使用 TZ 來推測時區。 5.4.0 不再根據操作系統的信息來推測時區,因為這是不可靠的。
范例
Example #1 獲取默認時區
<?php
date_default_timezone_set('Europe/London');
if (date_default_timezone_get()) {
echo 'date_default_timezone_set: ' . date_default_timezone_get() . '<br />';
}
if (ini_get('date.timezone')) {
echo 'date.timezone: ' . ini_get('date.timezone');
}
?>
以上例程的輸出類似于:
date_default_timezone_set: Europe/London date.timezone: Europe/London
Example #2 獲取一個時區的簡寫
<?php
date_default_timezone_set('America/Los_Angeles');
echo date_default_timezone_get() . ' => ' . date('e') . ' => ' . date('T');
?>
以上例程會輸出:
America/Los_Angeles => America/Los_Angeles => PST
參見
date_default_timezone_set() - 設定用于一個腳本中所有日期時間函數的默認時區 所支持的時區列表