CakeFest 2024: The Official CakePHP Conference

getdate

(PHP 4, PHP 5, PHP 7, PHP 8)

getdate获取日期/时间信息

说明

getdate(?int $timestamp = null): array

返回关联 array,包含 timestamp 或者当前本地时间(如果省略 timestamp 或为 null)的日期信息。

参数

timestamp

可选的 timestamp 参数是一个 int 的 Unix 时间戳,如未指定或是 null,参数值默认为当前本地时间。也就是说,其值默认为 time() 的返回值。

返回值

返回关联 array,包含 timestamp 相关信息。返回的关联数组中的元素如下:

返回的关联数组中的键元素
键名 说明 返回值例子
"seconds" 秒的数字表示 059
"minutes" 分钟的数字表示 059
"hours" 小时的数字表示 023
"mday" 月份中第几天的数字表示 131
"wday" 星期几的数字表示 0(周日)到 6(周六)
"mon" 月份的数字表示 112
"year" 4 位数字表示的完整年份 比如: 19992003
"yday" 一年中第几天的数字表示 0365
"weekday" 星期几的完整文本表示 SundaySaturday
"month" 月份的完整文本表示,比如 January 或 March JanuaryDecember
0 自从 Unix 纪元开始至今的秒数,和 time() 的返回值以及用于 date() 的值类似。 系统相关,通常从 -21474836482147483647

更新日志

版本 说明
8.0.0 现在 timestamp 允许为 null。

示例

示例 #1 getdate() 例子

<?php
$today
= getdate();
print_r($today);
?>

以上示例的输出类似于:

Array
(
    [seconds] => 40
    [minutes] => 58
    [hours]   => 21
    [mday]    => 17
    [wday]    => 2
    [mon]     => 6
    [year]    => 2003
    [yday]    => 167
    [weekday] => Tuesday
    [month]   => June
    [0]       => 1055901520
)

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top