【问题标题】:How to check hours in timestamp is in between a particular range of hours? [duplicate]如何检查时间戳中的小时数是否在特定的小时范围内? [复制]
【发布时间】:2012-06-08 11:38:03
【问题描述】:

可能重复:
How to convert Unix timestamp to hhmmss?

我的时间戳格式为:

1330559989

如何查看时间戳中的小时数在 6 小时到 23 小时之间?

有人可以帮帮我吗?

【问题讨论】:

    标签: php datetime timestamp


    【解决方案1】:

    date('H', 1330559989) 将以 24 小时格式为您提供带前导零的小时,在此示例中为:23

    还有一个用于时间戳小时的特定函数,称为 getdate,它提供了该信息的数组接口 (demo):

    getdate(1330559989)['hours']; # 23
    

    【讨论】:

      【解决方案2】:
      $hrs=date('H', 1330559989);
      if ($hrs>= 6 && $hrs<= 23) {
        // your code
      }
      

      【讨论】:

        【解决方案3】:

        如果您想检查从现在到给定时间戳之间的时间,那么您可以使用:

        <?php
            echo date("H", strtotime(now)-1330559989); // Displays the difference from now.
            echo date("H", 1330559989); // Displays that time!
        ?>
        

        希望这会有所帮助! :)

        【讨论】:

          猜你喜欢
          • 2018-12-28
          • 2020-07-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-06-22
          • 1970-01-01
          相关资源
          最近更新 更多