【发布时间】:2021-01-01 14:16:55
【问题描述】:
我想检查一个日期是今天、明天、昨天还是以前。 但是我的代码不起作用。
代码:
public function istimedate($timestamp=''){
$timestamp=date_create($timestamp);
$date = strtotime(date($timestamp,"Y-m-d"));
$current_Time = strtotime(date("Y-m-d"));
if($date == $current_Time) {
$day_time = 'Today';
} elseif(strtotime("-1 day", $date) == $current_Time) {
$day_time = 'Yesterday';
} elseif(strtotime("+1 day", $date) == $current_Time) {
$day_time = 'Tomorrow';
} else {
$day_time = 'Someday ago';
}
return $day_time;
}
$day = $this->istimedate('2021-01-01 09:33:04');
【问题讨论】:
-
欢迎来到 Stack Overflow。您应该告诉我们您的代码到底有什么问题。它不编译吗?是否计算错误的值?要改进您的问题,请阅读tour 和How do I ask a good question?。
标签: time simpledateformat magento-2.0