问题描述
我想检查日期是今天、明天、昨天还是上一个。 但是我的代码不起作用。
代码:
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');
解决方法
日期使用正确格式转换。$date = strtotime(date_format($timestamp,"Y-m-d"));
插入 $date = strtotime(date($timestamp,"Y-m-d"));