获取strtotime以查找给定时间的下一个时间戳


Get strtotime to find next timestamp at given time

我试图让strtotime给我一个时间戳,但我只知道它是一个小时和一分钟,它是下一行。Fx。

如果给定的小时和分钟是01:00(AM),我要求它返回01:00(上午)的时间戳,如果是前一天的19:00,我希望它返回第二天的01:00时间戳,但如果是在00:30午夜之后,它应该返回相同日期的01:00时间戳。

为了简化它,它是一个时间的下一次出现。

Strtotime给了我同一天的时间,如果不是下一次的话。

您可以轻松地生成时间戳,查看它是否已经过去,然后增加日期。

也许是这样的?

$timestamp = strtotime("1:00 am");
if($timestamp < time()) {
    $timestamp = strtotime("+1 day",$timestamp);
}

或者,如果你想把它收紧到一行:

$string = "1:00 am";
$timestamp = (strtotime($string) > time()) ? strtotime($string) : strtotime("tomorrow " . $string);