2013-02-26 86 views
0

我有兩個日期,從日期和日期。 說,txtEffectiveDate是26/02/2013和txtInactiveDate是28/02/2013,我需要在jsp我的標題爲26/02 27/02 and 28/02。我寫了一個util函數,它返回天差異。這是我迄今爲止取得的成就。如何在jsp中的日期之間進行迭代?

<table border="0" cellpadding="4" cellspacing="1"> 
      <tr>  
       <td width="100" class="boxBorderHeader141">Service NO.</td> 
       <% long diff= 0 ; 
        diff = DateUtil.getDifference(DateUtil.toUtilDate(request.getAttribute("txtEffectiveDate").toString()), DateUtil.toUtilDate(request.getAttribute("txtInactiveDate").toString())); 
       %> 
       <td width="100" class="boxBorderHeader141"><bean:write name="servicesForm" property="txtEffectiveDate" /></td>        
       <td width="100" class="boxBorderHeader141">Departure Time</td> 
       <td width="100" class="boxBorderHeader141">Depot Code</td> 
       <td width="100" class="boxBorderHeader141">Service Category</td> 
       <td width="100" class="boxBorderHeader141">Service Name</td> 
       <td>&nbsp;</td> 
      </tr> 
      </table> 

日期應該在服務編號和出發時間之間迭代?

任何幫助表示讚賞。

感謝

回答

0

在你的小腳本,計算其它日期

您的代碼

long diff= 0 ; 
diff = DateUtil.getDifference(DateUtil.toUtilDate(request.getAttribute("txtEffectiveDate").toString()), DateUtil.toUtilDate(request.getAttribute("txtInactiveDate").toString())); 

擴展

Calendar cal = Calendar.getInstance(); 
for(int i=0; i < diff; i ++){ 
    cal.setTime(DateUtil.toUtilDate(request.getAttribute("txtEffectiveDate").toString())); 
    cal.add(Calendar.DATE, i + 1); 
    java.util.Date newDate = cal.getDate(); 
    //  Display that new date as column 
} 
相關問題