【问题标题】:Getting the last second of the Day获取当天的最后一秒
【发布时间】:2011-01-06 06:32:47
【问题描述】:

在 PHP 5.2 中,如何获取一天中的最后一秒? time() + 86400 只得到第二天?

【问题讨论】:

    标签: php time timestamp timing


    【解决方案1】:
    echo date('r', strtotime('tomorrow') - 1);
    
    returns 'Mon, 18 Jan 2010 23:59:59'
    

    您需要处理闰秒(例如23:59:60

    【讨论】:

    • 闰秒与此无关。例如,“2008-12-31 23:59:60”与“2009-01-01 00:00:00”相同。引用unix-time.com:“无论一天有多长,Unix 时间数字每天都会增加 86400。”和“当插入闰秒时……Unix时间编号在闰秒期间不断增加……然后在闰秒结束时向下跳1,即第二天的开始。”跨度>
    • GZipp,所以你的意思是我的解决方案也是正确的? :D 很高兴了解闰秒,但我之前并不知道。
    【解决方案2】:
    strtotime('23:59:59');
    

    【讨论】:

      猜你喜欢
      • 2014-03-22
      • 1970-01-01
      • 2017-01-09
      • 2012-10-03
      • 1970-01-01
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      相关资源
      最近更新 更多