Forum und email

localtime

(PHP 4, PHP 5)

localtime — Get the local time

說明

array localtime ([ int $timestamp [, bool $is_associative ]] )

The localtime() function returns an array identical to that of the structure returned by the C function call.

參數

timestamp

選擇性 timestamp 參數是一個 integer 類型的 Unix 時間戳記,如果沒給予 timestamp 則其預設值是目前本地時間。換句話說,預設為 time() 函式的值。

is_associative

If set to FALSE or not supplied than the array is returned as a regular, numerically indexed array. If the argument is set to TRUE then localtime() is an associative array containing all the different elements of the structure returned by the C function call to localtime. The names of the different keys of the associative array are as follows:

  • "tm_sec" - seconds
  • "tm_min" - minutes
  • "tm_hour" - hour
  • "tm_mday" - day of the month Months are from 0 (Jan) to 11 (Dec) and days of the week are from 0 (Sun) to 6 (Sat).
  • "tm_mon" - month of the year, starting with 0 for January
  • "tm_year" - Years since 1900
  • "tm_wday" - Day of the week
  • "tm_yday" - Day of the year
  • "tm_isdst" - Is daylight savings time in effect

錯誤/例外

如果時區無效,每個對日期/時間函式的呼叫都會產生一個 E_NOTICE 訊息,如果使用系統設定或 TZ 環境變數則會產生 E_STRICT 消息。參見 date_default_timezone_set()

更新日誌

版本 說明
5.1.0

現在發出 E_STRICTE_NOTICE 時區錯誤。

範例

Example#1 localtime() example

<?php
$localtime 
localtime();
$localtime_assoc localtime(time(), true);
print_r($localtime);
print_r($localtime_assoc);
?>

上例的輸出類似於:

Array
(
    [0] => 24
    [1] => 3
    [2] => 19
    [3] => 3
    [4] => 3
    [5] => 105
    [6] => 0
    [7] => 92
    [8] => 1
)

Array
(
    [tm_sec] => 24
    [tm_min] => 3
    [tm_hour] => 19
    [tm_mday] => 3
    [tm_mon] => 3
    [tm_year] => 105
    [tm_wday] => 0
    [tm_yday] => 92
    [tm_isdst] => 1
)