What is the simplest way to convert 23-Mar-2011 to 23-03-2011 in Java?
Thanks everyone. This seem to solve the issue:
try {
Calendar cal = Calendar.getInstance();
cal.setTime(new SimpleDateFormat("dd-MMM-yyyy").parse("24-Nov-2002"));
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
System.out.println(sdf.format(cal.getTime()));
} catch (ParseException e) { e.printStackTrace(); }
Try this
String strDate="23-Mar-2011";
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
try {
Date varDate=dateFormat.parse(strDate);
dateFormat=new SimpleDateFormat("dd-MM-yyyy");
System.out.println("Date :"+dateFormat.format(varDate));
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
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