SimpleDateFormat的结果不正确

hap*_*ppy 0 java datetime date simpledateformat

我想转换Tue Jun 01 00:00:00 IST 11201-JUN-2012

我用了

 Calendar calendar = new GregorianCalendar(year, 6, Calendar.DAY_OF_MONTH); 
     Date maxDate=new Date();
     maxDate=calendar.getTime();  
     calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); 
      SimpleDateFormat s=new SimpleDateFormat("dd-mmm-yyyy");
       s.format(maxDate);
Run Code Online (Sandbox Code Playgroud)

但我明白了 30-000-0112

Jig*_*shi 5

使用CAPITAL M一个月,

 SimpleDateFormat s=new SimpleDateFormat("dd-MMM-yyyy");
Run Code Online (Sandbox Code Playgroud)

你也是先设置日期,然后你重置日历,我想你不想做什么,所以你需要把它改成如下

Date maxDate=new Date();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); 
maxDate=calendar.getTime();  
SimpleDateFormat s=new SimpleDateFormat("dd-MMM-yyyy");
s.format(maxDate);
Run Code Online (Sandbox Code Playgroud)

看到