【问题标题】:If current time is more than 30 seconds past time X (from the database)如果当前时间超过时间 X 30 秒(来自数据库)
【发布时间】:2011-03-04 10:51:06
【问题描述】:

如果当前时间 ($time) 超过时间 ($djs['currenttime']) 超过 30 秒,我将如何构造语句?会不会是这样的

如果($time => $djs['currenttime'])?我无法在 30 秒内弄清楚..:)。

谢谢:)。

【问题讨论】:

标签: php time if-statement


【解决方案1】:

您正在努力解决的 30 秒只是在增加 $djs['currenttime'] 的值的条件下添加的 +30

您可以使用time() 函数来获取实际时间。我假设djs['currenttime'] 是从数据库中提取的值。因此比较如下:

if(time() > $djs['currenttime'] + 30){
    //actions here;
}

time() 返回自 1970 年 1 月 1 日 00:00:00 GMT 以来的秒数,因此要使其正常工作,$djs['currenttime'] 变量的格式也应该是 unix 时间戳。如果没有,您需要先将其中一个转换为适当的格式。

【讨论】:

  • 啊,我明白了,所以它都以秒为单位,而不是毫秒或更小。谢谢。
  • 如果您使用微时间而不是时间,它将使用微秒,但时间本身使用秒作为单位。
【解决方案2】:
if ($time > ($djs['currenttime'] + 30))

假设这两个值都是实际时间戳而不是格式化字符串

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 2017-08-27
    • 2013-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多