【问题标题】:PHP - Checking if a timedate has pastPHP - 检查时间日期是否已经过去
【发布时间】:2013-10-31 01:02:40
【问题描述】:
$from = time();
$to = strtotime($row['clock']);
if($to<$from){
    echo("Time has past.");
}

我只是想用一个简单的 IF 语句检查时间是否已经过去。

目前,无论日期时间如何,if 语句始终为真。

$row['clock'] = 2013-10-31 00:04:00

【问题讨论】:

  • 次要评论 - 正确的语法是写“时间已经过去”。而不是“过去”。

标签: php if-statement time


【解决方案1】:

这在这里工作得很好。确保$row['clock'] 包含您认为的内容。

$from = time();
$to = strtotime('2013-11-01 00:00:00');
if($to<$from){
    echo("Time has past.");
}

在我的机器上没有回声,而:

$from = time();
$to = strtotime('2013-10-01 00:00:00');
if($to<$from){
    echo("Time has past.");
}

回声“时间已经过去。”。

除此之外,请检查您的服务器时间是否设置正确。

【讨论】:

  • 服务器上的时间很好等等。我正在使用它来检查倒数计时器是否已完成。它倒计时很好,但无论如何这个 if 语句仍然是正确的。
  • 2次是1383182400 1383185737
  • 问题原来是 PHP 时间。是+1小时。更改 php.ini 中的时区
猜你喜欢
  • 1970-01-01
  • 2012-07-07
  • 1970-01-01
  • 2011-12-26
  • 2023-01-15
  • 2018-03-24
  • 2019-02-25
  • 1970-01-01
相关资源
最近更新 更多