![](/img/trans.png)
[英]How do I get the unix timestamp of 6pm/7pm/8pm of the present day in php?
[英]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.