我有一个控制器操作,在其中我获取当前日期,如下所示:
$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
的两个日期,而无需转换为时间戳。