PHP,为什么PHP认识到5月1日不到4月28日



我试图将之前的日期与今天(5月1日(进行比较,但结果发现之前的日期比今天高。我想知道为什么会发生这种情况,以及如何解决?

PHP

$api_date = '2021-04-28T06:30:00Z';
$previous_date = date('d-m-Y , H:i', strtotime($api_date));
$today_date = date('d-m-Y , H:i');
if($previous_date <= $today_date)
print_r('true');
else{
print_r('false'); //will return this, why?
}

解决方案:只需将日期格式更改为年月日,thx更改为@Nigel Ren

$api_date = '2021-04-28T06:30:00Z';
$previous_date = date('Y-m-d , H:i', strtotime($api_date));
$today_date = date('Y-m-d , H:i');
if($previous_date <= $today_date)
print_r('true'); //will return this
else{
print_r('false');
}

最新更新