21.1.3 使用getdate()函数
能够确定当前时间的另一个很实用的函数是getdate()函数。该函数原型如下所示:
array getdate([int timestamp])
它以时间戳作为可选参数,返回一个相关数组,表示日期和时间的各个部分,如表21-2所示。
在数组中定义了以上数据后,可以很方便地将它们转换成任何所需的格式。数组的0元素(时间戳)可能没有什么用途,但是如果调用没有参数的getdate()函数,它将返回当前的时间戳。
<?php
$today=getdate();
print_r($today);
?>
produces something similar to the following output:
Array(
[seconds]=>45
[minutes]=>6
[hours]=>20
[mday]=>14
[wday]=>3
[mon]=>3
[year]=>2007
[yday]=>72
[weekday]=>Wednesday
[month]=>March
[0]=>1173917205
)