2017-04-11 73 views
0

我想計算兩個日期之間的差異,如果差異大於0並且< 50分鐘,我將顯示帶有下一個文本的文本視圖:「X until limit time」(它是準時的,但接近極限) 如果差異是< 0(這是晚了),textview應該說「X分鐘晚」用戶遲到的時間差,跟蹤

現在一切工作的第一個條件,但第二個,該數字有時顯示晚740分鐘或更大數字

Date fechaactual = new Date(); 
long diff = trackingfecha.getTime() - fechaactual.getTime(); 
long diferenciaminutos = diff/(60 * 1000); 
RunneableUpdateUI run = new RunneableUpdateUI(); 
if(diferenciaminutos < 50) { 
    if(diferenciaminutos >= 0) { 
     //Show the minutes close to some specific time 
     StringBuffer buffer = new StringBuffer(); 
     buffer.append("te quedan "); 
     String minutes = String.format("%02d", diferenciaminutos); 
     buffer.append(minutes); 
     buffer.append(" min"); 
     run.toUpdateValue = buffer.toString(); 
    } else { 
     //Here is the problem 
     StringBuffer buffer = new StringBuffer(); 
     String minutes = String.format("%02d", Math.abs(diferenciaminutos)); 
     buffer.append(minutes); 
     buffer.append(" min tarde"); 
     run.toUpdateValue = buffer.toString(); 
    } 
    timerHandler.post(run); 
} 
+0

爲什麼它不能延遲740分鐘? –

+0

這種情況發生在用戶遲到幾個小時後,差不多有12個小時 –

回答

-1
if (0<=x && x < 50) 
     { 
      // x time to reach 
     } 
     else 
     { 
      if (0> x) 
      { 
       // late 
      } 
     } 

    } 

其中x是你的時間差異