如何检查时间戳记是否在今天的午夜之后?

时间:2019-10-26 20:38:25

标签: php date time timestamp

我试图检查时间戳记是否从今天(午夜之后)开始。

例如,这是我要检查的时间戳:1572122130

我尝试过的事情:

<?php

$time = strtotime('today midnight') - 1572122130;

if($time < 86400){
    echo "timestamp is from today!"; //timestamp is from today (after midnight)
}

1 个答案:

答案 0 :(得分:0)

您可以简单地使用DateTime类。

$ts = 1572122130;

$today = (new \DateTime())->setTime(0, 0); // get tonight midnight

// compare the timestamp to the date above
var_dump(date_create_from_format('U', $ts) >= $today);