Hed*_*dam 2 php timestamp strtotime
我试图让 strtotime 给我一个时间戳,但我只知道这是一个小时和一分钟,它是下一个。外汇。
如果给定的小时和分钟是 01:00 (AM),我要求它返回 01:00 (AM) 的时间戳,如果是前一天的 19:00,我希望它返回 01 的时间戳: 00 第二天,但如果它是在 00:30 午夜之后,它应该返回同一日期的时间戳 01:00。
为简化起见,它是 NEXT 出现的时间。
Strtotime 给了我同一天的时间,如果不是下一次。
您可以轻松生成时间戳,查看它是否已经过去,然后增加日期。
也许是这样的?
$timestamp = strtotime("1:00 am");
if($timestamp < time()) {
$timestamp = strtotime("+1 day",$timestamp);
}
Run Code Online (Sandbox Code Playgroud)
或者,如果您想将其收紧为单线:
$string = "1:00 am";
$timestamp = (strtotime($string) > time()) ? strtotime($string) : strtotime("tomorrow " . $string);
Run Code Online (Sandbox Code Playgroud)