I am trying to format a string into specific date format but there is some problem in conversion. In converted string month is always coming “January”. Following is the code snippet:
String date = "30/10/2012-11:11:11";
DateFormat dateForm = new SimpleDateFormat("dd/mm/yyyy-hh:mm:ss");
try {
System.out.println(dateForm.parse(date));
}
catch (ParseException e) {
e.printStackTrace();
}
I am not able to get the reason behind this.
Please suggest.
As others have said, you should use
MMfor months – and I strongly suspect you always want to useHHfor hours, instead ofhh.HHis the 24 hour clock;hhis the 12 hour clock, usually used in conjunction with an AM/PM designator.Finally, you should consider what time zone and locale you want your
SimpleDateFormatto use. Even in this case where there aren’t any month or day names, I’d still specify the locale explicitly, to make it clear that you’re not trying to use any localized data.