【问题标题】:I want to get the timestamp of next day 12PM in PHP我想在 PHP 中获取第二天中午 12 点的时间戳
【发布时间】:2019-12-05 20:35:15
【问题描述】:

我想得到明天中午 12 点的时间戳,我可以使用下面的代码行来做到这一点

strtotime('tomorrow noon');

但我遇到的问题是,当当前时间是午夜 00:00 时,我正在获取第二天的时间戳,我想要这样的时间是午夜 00:00 时,它仍然应该给出时间戳新一天的中午而不是第二天。

【问题讨论】:

    标签: php strtotime timeslots


    【解决方案1】:

    你可以做一个简单的三元:

    strtotime((date('H:i') == '00:00' ? '' : 'tomorrow ').'noon');
    

    或者用一个简单的 if 情况:

    if (date('H:i') == '00:00') {
        $noon = strtotime('noon');
    } else {
        $noon = strtotime('tomorrow noon');
    }
    

    【讨论】:

    • @Slipstream 我不明白你的意思。
    • 对不起我的英语不好,我想说的是,我已经尝试在它失败之前使用那个逻辑。
    • @Slipstream 不用担心。你能解释一下你想要达到的目标吗?
    【解决方案2】:

    我想如果还没有中午,您可能希望在中午显示当前日期,否则显示明天中午的时间。如果是这种情况,以下内容可能会有所帮助:

    $noon = strtotime('now') < strtotime('noon') 
    ? strtotime('noon') 
    : strtotime('tomorrow noon')
    

    【讨论】:

      猜你喜欢
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      • 2012-10-19
      • 2015-07-23
      • 2022-01-16
      • 1970-01-01
      • 2011-06-14
      • 2019-06-10
      相关资源
      最近更新 更多