使用 Zend PHP Framework 2 将字符串转换为日期或获取当前日期

Converting string to date or getting the current date using Zend PHP Framework 2

我有一个控制器操作,我在其中获取当前日期,如下所示:

    $fullDate=date("Y-m-d");
    $date = strtotime($fullDate);
    $viewModel->setVariable("currentDate",$date);
// Here I would like to pass the variable to the View and then compare it with another date ... 

使用上面的方法,我在 var_dump($currentDate);

时得到了这个
int(1463587200)

这不是我所期待的...我需要一个格式为 2016-05-19(年-月-日)的日期...我怎样才能以有效的方式做到这一点???

strtotime 正在将您的格式化日期转换为 Unix 时间戳。只需删除它。

     $fullDate=date("Y-m-d");
     $viewModel->setVariable("currentDate",$fullDate);

您将能够比较此格式的两个日期 Y-m-d,而无需转换为时间戳。