Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a weird exception Unparseable date: "6 Aug 2012"

Tags:

java

android

I got a date time format - "dd MMM yyyy", when trying to parse "6 Aug 2012", I get an java.text.ParseException Unparseable date.

Every thing looks fine, do you see the problem?

like image 733
Chen Kinnrot Avatar asked Aug 05 '12 10:08

Chen Kinnrot


4 Answers

You need to mention the Locale as well...

Date date = new SimpleDateFormat("dd MMMM yyyy", Locale.ENGLISH).parse("6 Aug 2012");
like image 191
Bharat Sinha Avatar answered Nov 17 '22 06:11

Bharat Sinha


Use something like:

DateFormat sdf = new SimpleDateFormat("dd MMM yyyy", Locale.ENGLISH);
Date date = sdf.parse("6 Aug 2012");
like image 1
Reimeus Avatar answered Nov 17 '22 08:11

Reimeus


Use the split() function with the delimiter " "

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]);
like image 1
Kumar Vivek Mitra Avatar answered Nov 17 '22 07:11

Kumar Vivek Mitra


This should work for you. You will need to provide a 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");
like image 1
Durgadas Kamath Avatar answered Nov 17 '22 08:11

Durgadas Kamath