简体   繁体   English

我想在 PHP 中获取第二天中午 12 点的时间戳

[英]I want to get the timestamp of next day 12PM in PHP

i want to get the timestamp of tomorrow at 12PM, i can do this using the line of code below我想在下午 12 点获得明天的时间戳,我可以使用下面的代码行来做到这一点

strtotime('tomorrow noon');

But the problem am having is that, when the current time is 00:00 at midnight, am getting the next day timestamp, i want it such when the time is 00:00 at midnight, it should still give the timestamp of noon of the new day not the next day.但是我遇到的问题是,当当前时间是午夜 00:00 时,我正在获取第二天的时间戳,我希望它在午夜 00:00 时这样,它仍然应该给出中午的时间戳新的一天不是第二天。

You can do a simple ternary:你可以做一个简单的三元:

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

Or with a simple if case:或者用一个简单的 if 案例:

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

I'm imagining you might like to display the current day at noon if it is not yet noon, otherwise show the time tomorrow at noon.我想如果现在还不是中午,您可能希望在中午显示当前日期,否则在明天中午显示时间。 If this is the case, the following might be helpful:如果是这种情况,以下内容可能会有所帮助:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM