2009-09-13 27 views
0
GregorianCalendar startDate = new GregorianCalendar(2009, Calendar.JANUARY, 1); 
SimpleDateFormat sdf = new SimpleDateFormat("d/m/yyyy"); 
public void setStart() 
{ 
    startDate.setLenient(false); 
    System.out.println(sdf.format(startDate.getTime())); 
} 

當我運行此代碼時,我得到1/0/2009。當我改變月份時,我也會得到同樣的結果。它有什麼問題,我該如何解決它?GregorianCalendar個月

+0

只是FYI,我發佈到您的原始問題的解決方案有大寫M http://stackoverflow.com/questions/1416682/gregoriancalendar-constant-date/1416692#1416692 – cletus 2009-09-13 05:00:02

+0

是的,我沒有注意到它是大寫字母。謝謝 – Karen 2009-09-13 05:12:17

回答

1

小寫'm'表示小時內的分鐘數。您應該使用大寫'M'。

SimpleDateFormat sdf = new SimpleDateFormat("d/M/yyyy"); 

有關更多詳細信息,請參閱SimpleDateFormat JavaDoc。