vikash sinha vikash sinha - 4 months ago 9
Java Question

Date parse in java

I am not able to parse this string as date.
"01-09-14 01:56:58.000000000 PM"

SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm:ss.SSSZ aaa");
Date startDate = formatter.parse(date);


Thanks in advance

Answer
  1. Remove the Z because you have no timezone in your string.
  2. Use hh for 12 hours

    SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy hh:mm:ss.SSS aaa"); Date startDate = formatter.parse(date);

For more Information see the documentation of SimpleDateFormat

Comments