Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date convert dd-MMM-yyyy to dd-MM-yyyy in java

Tags:

java

date

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(); }
like image 627
Viren Pushpanayagam Avatar asked Mar 23 '11 05:03

Viren Pushpanayagam


1 Answers

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();
}
like image 190
Saurabh Avatar answered Oct 05 '22 09:10

Saurabh