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

时间:2016-05-19 14:39:43

标签: php date datetime zend-framework

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

    $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(年 - 月 - 日)...我怎么能这样做有效的方式???

1 个答案:

答案 0 :(得分:1)

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

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

您可以使用此格式Y-m-d比较两个日期,而无需转换为时间戳。