user1224036
user1224036

Reputation: 1008

Unable to parse this date

I am getting dates in this format 14-MAY-13 01.17.16.250000 PM and

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yy hh:mm:ss aaa");
  simpleDateFormat.parse("14-MAY-13 01.17.16.250000 PM")

Gives me this exception

java.text.ParseException: Unparseable date: "14-MAY-13 01.17.16.250000 PM" ..What should be format of simpledateformat?

Upvotes: 2

Views: 3704

Answers (5)

LaurentG
LaurentG

Reputation: 11827

The format must be corrected (see the javadoc for more information). You should also set the Locale to the SimpleDateFormat to be sure the month will be parsed with the correct language.

new SimpleDateFormat("dd-MMM-yy hh.mm.ss.SSSSSS aaa", Locale.US);

If you don't give the Locale, SimpleDateFormat will use the default locale of your system which can be not the locale of the given string input.

Upvotes: 3

commit
commit

Reputation: 4807

Simple date format and date formate should be same, try this

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yy hh:mm:ss:SSSSSS aaa");

Date d = simpleDateFormat.parse("14-MAY-13 01:17:16:250000 PM");

Upvotes: 0

Devolus
Devolus

Reputation: 22094

In your Formatstring you expect hh:mm:ss but in your input string your have hh.mm.ss and you also didn't include the miliseconds.

So the format string should be dd-MMM-yy hh.mm.ss.SSSSSS aaa

Upvotes: 0

AllTooSir
AllTooSir

Reputation: 49432

You need to use the SSSSSS for milliseconds and replace : with . to match this part 01.17.16.250000.

SimpleDateFormat simpleDateFormat = 
                 new SimpleDateFormat("dd-MMM-yy hh.mm.ss.SSSSSS aaa");

Upvotes: 1

darijan
darijan

Reputation: 9795

Try

new SimpleDateFormat("dd-MMM-yy hh.mm.ss.SSSSSS aaa");

Upvotes: 6

Related Questions