0

I have a string in this format dd-NameOfMonth-yy

example : String str="12-nov-12"

And i would like to convert it to a Date.

I tried the following code but i got the error :

java.text.ParseException: Unparseable date: "14-Sep-11"

DateFormat formatter = null;
Date convertedDate = null;
String ddMMMyy = "14-Sep-11";
formatter = new SimpleDateFormat("dd-MMM-yy");
convertedDate = (Date) formatter.parse(ddMMMyy);
System.out.println("Date from dd-MMM-yy String in Java : " + convertedDate);
Selma BA
  • 149
  • 3
  • 18
  • Works for me. What is your locale, i.e. is month 9 really abbreviated "Sep"? – Henry Jan 26 '16 at 13:45
  • yes is the month 9 , I didn't set the local but the local i need Frensh local. How can i set it? thx – Selma BA Jan 26 '16 at 13:47
  • Thank you Henry for your help , i just added the Local attribut to SimpleFormat() and it works very well: formatter = new SimpleDateFormat("dd-MMM-yy",Locale.FRANCE); – Selma BA Jan 26 '16 at 13:55

0 Answers0