【问题标题】:how to compare two timestamps in PHP? [duplicate]如何比较PHP中的两个时间戳? [复制]
【发布时间】:2018-01-10 19:45:55
【问题描述】:

在我的代码中,我有这样的场景:

<?php
     $start = "03:00:00:am";
     $end   = "08:00:00:pm";

      if($start > $end) {}   
?>

我尝试使用 unix 时间戳,但没有成功。

【问题讨论】:

标签: php


【解决方案1】:

试试这个,我不认为最后的 am, pm 是正确的格式,但是你应该可以用这种方式测试它们:

$start = strtotime("03:00:00");
$end   = strtotime("20:00:00");

if($start > $end) {}

【讨论】:

    【解决方案2】:

    使用此代码:

    <?php
    $start = strtotime("03:00:00");
    $end   = strtotime("20:00:00");
    
    if($start > $end) {
     echo "Yes";
    }
    else{
        echo "No";
    }
    ?>
    

    更多信息:http://php.net/manual/en/function.strtotime.php

    【讨论】:

      猜你喜欢
      • 2019-02-27
      • 2020-06-18
      • 2021-04-25
      • 2012-02-04
      • 1970-01-01
      • 1970-01-01
      • 2016-08-06
      • 2016-09-07
      • 2015-01-02
      相关资源
      最近更新 更多