Receive strange exception Unmatched date: "August 6, 2012"

I got the date time format - "dd MMM yyyy"trying to parse "August 6, 2012", I get java.text.ParseException. Unprecedented date.

Every thing looks great, do you see the problem?

+5
source share
4 answers

You must also specify Locale ...

Date date = new SimpleDateFormat("dd MMMM yyyy", Locale.ENGLISH).parse("6 Aug 2012");
+7
source

Use something like:

DateFormat sdf = new SimpleDateFormat("dd MMM yyyy", Locale.ENGLISH);
Date date = sdf.parse("6 Aug 2012");
+1
source

This should work for you. You will need to specify the locale

Date date = new SimpleDateFormat("dd MMM yyyy", Locale.ENGLISH).parse("6 Aug 2012");

or

Date date = new SimpleDateFormat("dd MMM yyyy", new Locale("EN")).parse("6 Aug 2012");
+1
source

Use the split()delimited function " "

String s = "6 Aug 2012";

String[] arr = s.split(" ");

int day = Integer.parseInt(arr[0]);
String month = arr[1];
int year = Integer.parseInt(arr[2]);
+1
source

All Articles