2015-06-08 60 views
0

IM在我的網站上顯示日期和時間的量,直到某個事件開始,我創建了下面的代碼:PHP的時間和小時小於零(0)

我的問題:

天數和小時雲在負(小於零)時,有沒有天,其餘的沒有什麼不時間應顯示

enter image description here

//cur date 
    $curDate = date("Y-m-d"); 
     //future date + 7days 
     $date = date('Ymd'); 
     $date = strtotime($date); 
     $date = strtotime("+7 day", $date); 
     $date = date('Y-m-d', $date); 



    //return days and hours remaining until KO 
      $calcDate = $gameDate.$time; 
       $calcDate = strtotime(str_replace('/', '-', $gameDate)); 
      $remaining = $calcDate - time(); 
       $days_remaining = floor($remaining/86400); 
       $hours_remaining = floor(($remaining % 86400)/3600); 
    //echo in index.php display in if statments 

    if($days_remaining<0&&$hours_remaining<0){ 
      echo''; 
      } 
    if($days_remaining == 0){ 
     echo 'Starts In: <span class="timeSpan">'.$hours_remaining.'</span> Hours'; 
        } 
        else if($days_remaining != 0){ 

         echo' Starts In: <span class="timeSpan">'.$days_remaining.'</span> Days And <span class="timeSpan">'.$hours_remaining.'</span>Hours';   
        } 
+0

你試過'如果($ DAYS_REMAINING <= 0){ '在最後的if/else語句中? –

+0

您的代碼不完整。什麼是時間和比賽日期? – wonderb0lt

+0

@caCtus即時通知 –

回答

0

$days_remaining AND $hours_remaining小於0時,仍然會轉到最後的if/else聲明。當你不顯示任何東西,如果都小於零,我會在這最後if/else去只有其中一個是大於零:

if($days_remaining>0 || $hours_remaining>0){ 
// You have something to display 

    if($days_remaining <= 0){ 
    // Something with only hours 
     echo 'Starts In: <span class="timeSpan">'.$hours_remaining.'</span> Hours'; 
    } 
    else { 
    // Something with days and hours 
     echo' Starts In: <span class="timeSpan">'.$days_remaining.'</span> Days And <span class="timeSpan">'.$hours_remaining.'</span>Hours';   
    } 
} 
+0

caCtus我要去嘗試你的代碼會讓你知道謝謝 –

1

替換:

if($days_remaining == 0){ 

有了:

if($days_remaining <= 0){ 

這樣,您將檢查剩餘天數爲0或小於0,我相信,你將需要添加一個類似的檢查爲我做的時間沒有看到你的代碼,但應該是相同的條件。

+0

感謝隊友,但即時得到相同的結果 –