【问题标题】:PHP How to get timestamp of day / hour from timestampPHP如何从时间戳获取日/小时的时间戳
【发布时间】:2015-10-03 11:32:30
【问题描述】:

我想获取当前小时和当天的时间戳。我该怎么做?

我将时间戳作为日期时间存储在我的数据库中,所以我想像这样比较我的数据:

  • 当前小时插入了多少条记录
  • 当天插入了多少条记录

感谢您的帮助

【问题讨论】:

  • 使用 php date 函数 date('h',strtotime('your_timestamp')) 小时和 date('d',strtotime('your_timestamp')) 一天

标签: php timestamp


【解决方案1】:

你可以使用mktime函数,只传递你想要的细节,0传递给其他人(比如分钟和秒)

int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )

鉴于该参数列表,您将拥有类似的代码

$timestamp = mktime(date("H"),0,0,date("n"),date("j"),date("Y"));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-22
    • 2019-08-09
    • 2012-04-15
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多