代码之家  ›  专栏  ›  技术社区  ›  Sam Johannes Rudolph

如果当前时间超过时间X 30秒(来自数据库)

  •  4
  • Sam Johannes Rudolph  · 技术社区  · 15 年前

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

    如果( $time => $djs['currenttime'] )? 我无法用30秒的时间来理解。

    谢谢:)。

    2 回复  |  直到 15 年前
        1
  •  6
  •   Juan Cortés    10 年前

    +30 $djs['currenttime'] .

    你可以用 time() 函数获取实际时间。我是这么想的 djs['currenttime']

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

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

        2
  •  3
  •   Mark Baker    15 年前
    if ($time > ($djs['currenttime'] + 30))
    

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