我有一个控制器动作,我在其中获取如下的当前日期:
$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(年 - 月 - 日)...我怎么能这样做有效的方式???
答案 0 :(得分:1)
此strtotime
正在将您的格式化日期转换为Unix时间戳。只需删除它。
$fullDate=date("Y-m-d");
$viewModel->setVariable("currentDate",$fullDate);
您可以使用此格式Y-m-d
比较两个日期,而无需转换为时间戳。