-2

可能重复:
如何将 Unix 时间戳转换为 hhmmss?

我的时间戳格式为:

1330559989

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

有人能帮助我吗?

4

3 回答 3

2

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

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

getdate(1330559989)['hours']; # 23
于 2012-06-08T11:39:32.777 回答
2
$hrs=date('H', 1330559989);
if ($hrs>= 6 && $hrs<= 23) {
  // your code
}
于 2012-06-08T11:43:06.317 回答
1

如果要检查从现在到给定时间戳之间的时间,则可以使用:

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

希望这可以帮助!:)

于 2012-06-08T11:40:21.213 回答