PHP | localtime()函数

localtime()函数是PHP中的一个内置函数,用于返回本地时间。localtime()函数返回的数组类似于C函数调用返回的结构。$timestamp和$is_作为参数发送给localtime()函数,它返回一个包含Unix时间戳组件的数组。

null

语法:

array localtime( $timestamp, $is_associative )

参数: 此函数接受两个参数,如上所述,如下所述。

  • $timestamp: 它是一个可选参数,用于指定Unix时间戳。其默认值为当前本地时间。
  • $is_关联: 它是一个可选参数,指定是返回关联数组还是索引数组。关联数组的值为:
    • tm_秒: 秒,0到59
    • 吴敏: 0到59分钟
    • tm_小时: 小时,0到23
    • 星期四: 每月1日至31日
    • tm_mon: 每年的月份,从1月0日到12月11日
    • tm_年: 自1900年以来
    • 今天: 一周中的第几天,0(太阳)到6(周六)
    • tm_yday: 一年中的某一天,0到365
    • tm_isdst: 夏令时有效吗?如果是,则为正;如果不是,则为0;如果未知,则为负。

返回值: 此函数返回包含Unix时间戳组件的数组。

例外情况:

  • 如果指定的时区无效,localtime()函数将生成一个E_通知。
  • 如果使用系统设置或TZ环境变量,localtime()函数将生成E_STRICT或E_警告消息

下面的程序演示了PHP中的localtime()函数:

项目1:

<?php
// Displaying the local time as
// a numerically indexed array
echo ( "The local time is :" );
print_r(localtime());
?>


输出:

The local time is :Array
(
    [0] => 22
    [1] => 24
    [2] => 10
    [3] => 28
    [4] => 7
    [5] => 118
    [6] => 2
    [7] => 239
    [8] => 0
)

项目2:

<?php
// Displaying the local time as
// an associative array
echo ( "The local time is :" );
print_r(localtime(time(), true));
?>


输出:

The local time is :Array
(
    [tm_sec] => 23
    [tm_min] => 24
    [tm_hour] => 10
    [tm_mday] => 28
    [tm_mon] => 7
    [tm_year] => 118
    [tm_wday] => 2
    [tm_yday] => 239
    [tm_isdst] => 0
)

相关文章:

参考: http://php.net/manual/en/function.localtime.php

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享