PHP检查时间是否在范围内,质疑通用解决方案

编程入门 行业动态 更新时间:2024-10-26 16:21:13
本文介绍了PHP检查时间是否在范围内,质疑通用解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须检查当前的白天是否在特定范围内.我上网查找了类似的几种解决方案:

I have to check if the current daytime falls in a specific range. I looked up the internet and found several similar solutions like this one:

$now = date("His");//or date("H:i:s") $start = '130000';//or '13:00:00' $end = '170000';//or '17:00:00' if($now >= $start && $now <= $end){ echo "Time in between"; } else{ echo "Time outside constraints"; }

如果两个条件都必须成立,那么当我们假设$ start为06:00:00和$ end为02:00:00时,如何达到这个条件.

If both conditions have to be true, how can this bis achieved when we assume that $start is 06:00:00 and $end is 02:00:00.

如果我们假设它是01:00:00,那么在这种情况下第一个条件就不能成立.

If we make the assumption that it is 01:00:00, in this case the first condition can't be true.

有人有不同的想法来解决这个问题吗?

Has anybody an idea to handle this problem differently?

谢谢!

推荐答案

自然,您必须在比较中考虑日期.

Naturally, you'd have to account for date in your comparisons.

<?php $start = strtotime('2014-11-17 06:00:00'); $end = strtotime('2014-11-18 02:00:00'); if(time() >= $start && time() <= $end) { // ok } else { // not ok }

更多推荐

PHP检查时间是否在范围内,质疑通用解决方案

本文发布于:2023-11-29 01:45:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644798.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:范围内   解决方案   时间   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!