PHP getdate函数获取日期时间关联数组
本示例演示了如何在PHP中利用getdate函数获取当前日期与时间,并将其组织为关联数组形式。相关内容可供开发者参考学习。
getdate函数的主要功能是获取当前的日期和时间,它可以将操作系统提供的时间或一个关联数组转换为UNIX风格的整数时间戳。
该函数的语法结构如下所示。
array getdate ();
array getdate (integer $Time);
以下是具体的参数说明: Arguments
$Time The number of seconds since midnight before January 1, 1970. (UNIX style.) Default The default is the current date and time from the operating system.)
函数返回一个关联数组,其中包含以下字段:
mon 一年中的月份,以数字表示(1..12) mday 一个月中的第几天(1..31) year 四位数的年份 hours 一天中的小时数(0..23) minutes 一小时内的分钟数(0..59) seconds 一分钟内的秒数(0..59) month 一年中的月份,以英文单词表示(January..December) yday 一年中的第几天(0..365) wday 一周中的第几天,以数字表示(0..6) weekday 一周中的第几天,以英文单词表示(Sunday..Saturday) 0 自1970年1月1日午夜以来的秒数
以下是一个具体的使用示例:
<?php
$Now = getdate();
foreach ($Now as $Key => $Value) {
echo "$Key => $Value\n";
}
?>
代码执行后的输出结果如下:
seconds => 59
minutes => 14
hours => 7
mday => 26
wday => 6
mon => 12
year => 2009
yday => 359
weekday => Saturday
month => December
0 => 1261811699
希望上述内容能对您的PHP编程实践有所帮助。