Reputation: 1008
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
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
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
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
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