首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

localtime

(PHP 4, PHP 5, PHP 7)

localtime - 获取当地时间

描述

代码语言:javascript
复制
array localtime ([ int $timestamp = time() [, bool $is_associative = false ]] )

localtime()函数返回相同,由C函数调用返回的结构的阵列。

参数

timestamp

可选timestamp参数是一个整数Unix时间戳,默认为当前本地时间,如果timestamp没有给出。换句话说,它默认为time()的值。

is_associative

如果设置为FALSE或不提供,那么数组将作为常规的数字索引数组返回。如果参数设置为TRUE然后localtime()返回一个包含由C函数调用的localtime返回的结构的所有的不同元件的关联数组。关联数组的不同键的名称如下所示:

  • "tm_sec" - seconds, 0 to 59
  • "tm_min" - minutes, 0 to 59
  • "tm_hour" - hours, 0 to 23
  • "tm_mday" - day of the month, 1 to 31
  • "tm_mon" - month of the year, 0 (Jan) to 11 (Dec)
  • "tm_year" - years since 1900
  • "tm_wday" - day of the week, 0 (Sun) to 6 (Sat)
  • "tm_yday" - day of the year, 0 to 365
  • “tm_isdst” - 实际上是夏令时吗?如果是,则为正;否则为0 ;如果未知,则为负。

错误/异常

如果使用系统设置或TZ环境变量E_NOTICE,则每次调用日期/时间函数都会生成一个如果时区无效的信息和/或a E_STRICTE_WARNINGmessage。另请参阅date_default_timezone_set()

Changelog

版本

描述

5.1.0

现在发出E_STRICT和E_NOTICE时区错误。

示例

Example #1 localtime() example

代码语言:javascript
复制
<?php
$localtime?=?localtime();
$localtime_assoc?=?localtime(time(),?true);
print_r($localtime);
print_r($localtime_assoc);
?>

上面的例子会输出类似于:

代码语言:javascript
复制
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
)

另请参阅

  • getdate() - Get date/time information

← idate

microtime →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com