php超过一定时间 [英] php greater than certain time

查看:74
本文介绍了php超过一定时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的函数,根据一天中的时间输出2行不同的文本。我希望它在下午4点之后说 - 第二天发货将在第二天处理。

I am trying to make a simple function to output 2 different lines of text depending on the time of the day. I want it to say after 4pm - Next day delivery will be processed the following day.

到目前为止我写了这个:

I have wrote this so far:

<?php

   $currentTime = time() + 3600;
   echo date('H:i',$currentTime);                 

?>   

但是由于date函数返回一个字符串,我不确定如何使用IF语句来检查是否时间大于16:00。

However as the date function returns a string, I am unsure of how to use an IF statement to check whether the time is greater than 16:00.

推荐答案

应该这样做

if (((int) date('H', $currentTime)) >= 16) {
  // .. do something
}

因为PHP是弱类型的,你可以省略(int) -casting。

Because PHP is weak-typed you can omit the (int)-casting.

作为旁注:如果你命名一个变量 $ currentTime ,你就不应该' t加1小时,因为那时它不再是当前时间,而是将来一小时;)完全

As a sidenote: If you name a variable $currentTime, you shouldn't add 1 hour to it, because then its not the current time anymore, but a time one hour in the future ;) At all

if (date('H') >= 16) { /* .. */ }

这篇关于php超过一定时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆