目录

PHP localtime() 函数

❮ PHP 日期/时间参考

示例

将本地时间打印为索引数组和关联数组:

<?php
print_r(localtime());
echo "<br><br>";
print_r(localtime(time(),true));
?>
亲自试一试 »

定义和用法

localtime() 函数返回当地时间。


语法

localtime( timestamp, is_assoc)

参数值

Parameter Description
timestamp Optional. Specifies a Unix timestamp that defaults to the current local time, time(), if no timestamp is specified
is_assoc Optional. Specifies whether to return an associative or indexed array. FALSE = the array returned is an indexed array. TRUE = the array returned is an associative array. FALSE is default.

The keys of the associative array are:

  • [tm_sec] - seconds
  • [tm_min] - minutes
  • [tm_hour] - hour
  • [tm_mday] - day of the month
  • [tm_mon] - month of the year (January=0)
  • [tm_year] - Years since 1900
  • [tm_wday] - Day of the week (Sunday=0)
  • [tm_yday] - Day of the year
  • [tm_isdst] - Is daylight savings time in effect


技术细节

返回值: 返回一个包含 Unix 时间戳组成部分的数组
PHP 版本: 4+
PHP 变更日志: PHP 5.1:现在出现 E_STRICT 和 E_NOTICE 时区错误

❮ PHP 日期/时间参考