2013-06-25 43 views

回答

1

public static Date getCurrentDatePlusMonth(int month) 
    { 
     Calendar calendar = Calendar.getInstance(); 
     calendar.setTime(new Date()); 
     calendar.add(Calendar.MONTH, month); 
     Date newDate = calendar.getTime(); 
     return newDate; 
    } 
8

用這個方法很簡單

短短一個月添加到當前日期

0

選中此

Calendar date = Calendar.getInstance(); 
System.out.println("Today date "+date.getTime()); 
date.add(Calendar.MONTH, 1); 
System.out.println("Next month date "+date.getTime()); 

的輸出將是

Today date Tue Jun 25 11:33:12 IST 2013 
Next month date Thu Jul 25 11:33:12 IST 2013 
0

用這個方法很簡單:

public static Date getPrevMonthDays() { 
       Calendar cl = Calendar.getInstance(); 
       if (displayedDate == null) 
        displayedDate = new Date(); 
       cl.setTime(displayedDate); 
       cl.add(Calendar.MONTH, -1); 
       displayedDate = cl.getTime(); 
       return displayedDate ; 

      } 

      public static Date getNextMonthDays() { 
       Calendar cl = Calendar.getInstance(); 
       if (displayedDate == null) 
        displayedDate = new Date(); 
       cl.setTime(displayedDate); 
       cl.add(Calendar.MONTH, 1); 
       displayedDate = cl.getTime(); 
       return displayedDate ; 

      } 
+0

隨時歡迎:) –

相關問題