(PHP 4, PHP 5)
localtime — 取得本地时间
$timestamp
[, bool $is_associative
]] )
localtime() 函数返回一个数组,其结构和
C 函数调用返回的完全一样。 localtime()
的第一个参数是时间戳,如果没有给出则使用从
time() 返回的当前时间。第二个参数是
is_associative
,如果设为 FALSE
或未提供则返回的是普通的数字索引数组。如果该参数设为 TRUE
则
localtime() 函数返回包含有所有从
C 的 localtime 函数调用所返回的不同单元的关联数组。关联数组中不同的键名为:
Note: 月份从 0(一月)到 11(十二月),星期数从 0(星期天)到 6(星期六)。
Example #1 time() 例子
<?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 [9] => 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 )
timestamp
可选的 timestamp
参数是一个 integer 的 Unix
时间戳,如未指定,参数值默认为当前本地时间。也就是说,其值默认为
time() 的返回值。
is_associative
If set to FALSE
or not supplied then the array is returned as a regular,
numerically indexed array. If the argument is set to TRUE
then
localtime() returns 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:
在每 次调用日期/时间函数时,如果时区无效则会引发 E_NOTICE
错误,如果使用系统设定值或 TZ
环境变量,则会引发 E_STRICT
或 E_WARNING
消息。参见
date_default_timezone_set()
版本 | 说明 |
---|---|
5.1.0 |
现在发布 |
Example #2 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 )