得到正确的月份格式日期java

可以任何帮助,如何从像这样的“2014-01-10T09:41:16.000 + 0000”字符串中获取正确的日期我的代码是:

String strDate = "2014-01-10T09:41:16.000+0000"; String day = ""; String format = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; Locale locale = new Locale("es", "ES"); SimpleDateFormat formater = new SimpleDateFormat(format, locale); formater.setTimeZone(TimeZone.getTimeZone("Europe/Madrid")); Calendar cal = Calendar.getInstance(); try { cal.setTimeInMillis(formater.parse(strDate).getTime()); String offerDate = cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR); System.out.println(offerDate); } catch (Exception e){ System.out.println(e.getMessage()); } 

在结果我给出这样的东西:“10-0-2014”,我希望结果像“10-01-2014”

提前致谢 :)

文件说明:

java.util.Calendar.MONTH

MONTH public static final int MONTH get和set的字段编号,表示月份。 这是特定于日历的值。 格里高利和朱利安日历中的第一个月是1月,即0; 最后一个取决于一年中的月数。

– > Calendar.MONTH的计数从0开始

我认为最简单的方法是使用另一个格式化程序对象来进行格式化,而不是自己构建它:

 try { Date d = new Date(cal.setTimeInMillis(formater.parse(strDate).getTime())); SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy"); String offerDate = format.format(d); System.out.println(offerDate); } catch (Exception e){ System.out.println(e.getMessage()); }