1

I'm trying to parse a (String) date into Date object, but no matter what pattern I use for SimpleDateFormat, I simply can't make it work, I always end up with getting a ParseException.

Code:

SimpleDateFormat sdf = new SimpleDateFormat("E MMM, d, h:mm a", Locale.US);

String strDate = "Tue Sep, 18, 3:30 AM";
Date newDate = null;

newDate = sdf.parse(strDate);

The above code gives me a Exception: java.text.ParseException: Unparseable date: "Tue Sep, 18, 3:30 AM".

I've even tried writing the string date directly into the parse method;

newDate = sdf.parse("Tue Sep, 18, 3:30 AM");

But that doesn't make any difference.

I'm cleary doing something wrong, but I just don't see where. I've read http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html over and over, and tried different SimpleDateFormat#pattern but haven't manage to solve it.

2
  • The code doesn't throw any Exception for me. Commented Sep 19, 2012 at 18:58
  • For me two. Works like a charm Commented Sep 19, 2012 at 18:58

1 Answer 1

1

Everything should be fine with that.. Try removing the locale, sometimes that can cause strange errors depending on the environment.

Sign up to request clarification or add additional context in comments.

1 Comment

I have no explanation, but it "just works" for me now, I think this might've been a problem with Dropbox syncing my folder and perhaps locking the files as NetBeans was compiling and running it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.