繁体   English   中英

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

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

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

strtotime('tomorrow noon');

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

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

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

或者用一个简单的 if 案例:

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

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

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

暂无
暂无

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

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