How to convert 2013-06-24 to 24 Jun 2013? I am using the below code.
date1="2013-06-24";
SimpleDateFormat d= new SimpleDateFormat("dd MMM yyyy");
try{
date2 = d.parse(date1);
}catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
But I am getting this error "java.text.ParseException: Unparseable date: "2013-06-24" (at offset 4)"
You need two DateFormat
instances: One to parse the original String
, and another to output the one you want.
DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
DateFormat outputFormat = new SimpleDateFormat("dd MMM yyyy");
String inputDateStr="2013-06-24";
Date date = inputFormat.parse(inputDateStr);
String outputDateStr = outputFormat.format(date);