如何在 PHP 中获取当前日期/时间作为日期对象
如何将今天的日期作为日期对象?
我试图计算某个开始日期和今天之间的差异。以下内容将不起作用,因为返回的是数组而不是日期对象:getdate()
$today = getdate();
$start = date_create('06/20/2012');
$diff = date_diff($start, $today);
echo($today . '<br/>' . $start . '<br/>' . $diff);
输出:
数组 ( [秒] => 8 [分钟] => 1 [小时] => 16 [mday] => 11 [wday] => 1 [星期一] => 6 [年] => 2012 [yday] => 162 [工作日] => 星期一 [月] => 六月 [0] => 1339455668 )
DateTime Object ( [date] => 2012-06-20 00:00:00 [timezone_type] => 3 [时区] =>美国/Los_Angeles )