0

I am receiving Date Strings in this Format dd-MMM-yyyy I am intending to convert the Strings to format yyyy-MM-dd by trying to parse the String but I am getting an error

Unparseable date: 01-AUG-2014

I am trying to do:

SimpleDateFormat form new SimpleDateFormat ("yyyy-MM-dd");
String datefrom = "01-AUG-2014"
Date dfrom = form.parse(datefrom);//getting error here

How can I convert the String 01-AUG-2014 to 2014-08-01?

Stanley Mungai
  • 4,044
  • 30
  • 100
  • 168

1 Answers1

2

It should be dd-MMM-yyyy use MMM instead for Month name to parse and than use format on date object you get from parsing.

FOR EXAMPLE

    SimpleDateFormat form = new SimpleDateFormat ("dd-MMM-yyyy");//For parsing
    String datefrom = "01-Aug-2014";
    Date date=form.parse(datefrom);
    SimpleDateFormat myForm = new SimpleDateFormat ("yyyy-MM-dd");//for formating
    System.out.println(myForm.format(date));//new formatted String
   //String formatterDate=myForm.format(date);
akash
  • 22,664
  • 11
  • 59
  • 87