未来最近的上午10点



有没有办法使用strtotime来获得下一个,比如将来上午 10 点?如果是上午9:59,那么下一个上午10点就是今天。如果是上午 10:00,下一个上午 10 点就是明天。 strtotime('next 10am')不起作用。

解决方案不需要使用strototime .建议?

一个简单的if就可以了

$time = time() < strtotime('10:00am')
   ? strtotime('10:00am')
   : strtotime('tomorrow 10:00am');
换句话说:如果当前时间在今天上午 10 点之前,那么时间是今天上午 10 点

,否则时间是明天上午10 点

最新更新