I am having problem with this small piece of code
SimpleDateFormat sf = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
String str = "2010-03-13 01:01:22";
Date date = sf.parse(str);
SimpleDateFormat f = new SimpleDateFormat("d MMM yyyy hh:mm aaa");
System.out.println(" Date " + f.format(date));
Output :
Date 13 Jan 2010 01:01 AM
The code seems to be fine but still I am getting month name wrong. Please help !! Thanks.
You are using minute instead of month in your pattern. It should be:
yyyy-MM-dd HH:mm:ss
mm
stands for minute. You should use MM
when parsing month:
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With