2009-09-13 50 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。