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 s
Please use "dd/MM/yyyy-hh:mm:ss"
As others have said, you should use MM
for months - and I strongly suspect you always want to use HH
for hours, instead of hh
. HH
is the 24 hour clock; hh
is 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 SimpleDateFormat
to 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.
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy-HH:mm:ss", Locale.US);
// TODO: Set the time zone appropriately
Use MM
instead of mm
for the date portion of your format string. mm
is for minutes, not months.
Reference: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html