PHPlocaltime()
函数用于以关联数组的形式打印时间。它返回当地时间。
语法
localtime(timestamp,is_assoc);
参数
参数 | 描述 | 必须/可选 |
---|---|---|
timestamp | 指定 Unix 时间戳 | 可选 |
is_assoc | 指定是否返回关联数组或索引数组。 | 可选 |
例子1
<?php
print_r(localtime());
echo "<br><br>";
print_r(localtime(time(),true));
?>
输出:
Array
(
[0] => 44
[1] => 2
[2] => 10
[3] => 18
[4] => 2
[5] => 123
[6] => 6
[7] => 76
[8] => 0
)
<br><br>Array
(
[tm_sec] => 44
[tm_min] => 2
[tm_hour] => 10
[tm_mday] => 18
[tm_mon] => 2
[tm_year] => 123
[tm_wday] => 6
[tm_yday] => 76
[tm_isdst] => 0
)
(
[0] => 44
[1] => 2
[2] => 10
[3] => 18
[4] => 2
[5] => 123
[6] => 6
[7] => 76
[8] => 0
)
<br><br>Array
(
[tm_sec] => 44
[tm_min] => 2
[tm_hour] => 10
[tm_mday] => 18
[tm_mon] => 2
[tm_year] => 123
[tm_wday] => 6
[tm_yday] => 76
[tm_isdst] => 0
)
例子2
<?php
$localtime = localtime();
$localtime_assoc = localtime(time(), true);
print_r($localtime);
print_r($localtime_assoc);
?>
输出:
Array
(
[0] => 0
[1] => 3
[2] => 10
[3] => 18
[4] => 2
[5] => 123
[6] => 6
[7] => 76
[8] => 0
)
Array
(
[tm_sec] => 0
[tm_min] => 3
[tm_hour] => 10
[tm_mday] => 18
[tm_mon] => 2
[tm_year] => 123
[tm_wday] => 6
[tm_yday] => 76
[tm_isdst] => 0
)
(
[0] => 0
[1] => 3
[2] => 10
[3] => 18
[4] => 2
[5] => 123
[6] => 6
[7] => 76
[8] => 0
)
Array
(
[tm_sec] => 0
[tm_min] => 3
[tm_hour] => 10
[tm_mday] => 18
[tm_mon] => 2
[tm_year] => 123
[tm_wday] => 6
[tm_yday] => 76
[tm_isdst] => 0
)