I got the date time format - "dd MMM yyyy"trying to parse "August 6, 2012", I get java.text.ParseException. Unprecedented date.
"dd MMM yyyy"
Every thing looks great, do you see the problem?
You must also specify Locale ...
Date date = new SimpleDateFormat("dd MMMM yyyy", Locale.ENGLISH).parse("6 Aug 2012");
Use something like:
DateFormat sdf = new SimpleDateFormat("dd MMM yyyy", Locale.ENGLISH); Date date = sdf.parse("6 Aug 2012");
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");
Use the split()delimited function " "
split()
" "
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]);