Ada*_*oss 32 php date strtotime
如果当前时间是当天下午2点之前,我需要检查PHP.
我之前的strtotime日期已经完成了这个,但是这次它只有一个时间,所以显然每天0.00将重置时间,并且布尔值将重置false为true.
if (current_time < 2pm) {
// do this
}
Run Code Online (Sandbox Code Playgroud)
Tom*_*Tom 68
if (date('H') < 14) {
$pre2pm = true;
}
Run Code Online (Sandbox Code Playgroud)
有关日期函数的更多信息,请参阅PHP手册.我使用了以下时间格式化程序:
H = 24小时格式的一小时(00到23)
Mer*_*ham 26
尝试:
if(date("Hi") < "1400") {
}
Run Code Online (Sandbox Code Playgroud)
请参阅:http://php.net/manual/en/function.date.php
H 24-hour format of an hour with leading zeros 00 through 23
i Minutes with leading zeros 00 to 59
Run Code Online (Sandbox Code Playgroud)
Joh*_*hnP 13
你可以通过时间
if (time() < strtotime('2 pm')) {
//not yet 2 pm
}
Run Code Online (Sandbox Code Playgroud)
或者也明确地传递日期
if (time() < strtotime('2 pm ' . date('d-m-Y'))) {
//not yet 2 pm
}
Run Code Online (Sandbox Code Playgroud)
使用 24 小时来解决问题,如下所示:
$time = 1400;
$current_time = (int) date('Hi');
if($current_time < $time) {
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
所以 2PM 相当于 24 小时内的 14:00。如果我们从 time 中删除冒号,那么我们可以在比较中将其评估为整数。
有关日期函数的更多信息,请参阅 PHP 手册。我使用了以下时间格式化程序:
H = 小时的 24 小时格式(00 到 23)
i = 带前导零的分钟数(00 到 59)