2

I am getting parse exception while running the below code, Is there anything wrong in the format ?

try {
    String Resolved= "17-04-2015 03:54" ;
    Date date  = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss z").parse(Resolved);
} catch (ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
1
  • 2
    I dont see seconds and a timezone specifier? Commented Dec 1, 2015 at 13:03

2 Answers 2

7

Your format string is: "dd-MM-yyyy HH:mm:ss z".

z represents the timezone. You don't have a timezone in the string you try to parse: "17-04-2015 03:54". (And you don't have seconds).

Change your format string to: "dd-MM-yyyy HH:mm" and you should be fine!

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

Comments

1

For your case, change

Date date  = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss z").parse(Resolved);

to

Date date  = new SimpleDateFormat("dd-MM-yyyy HH:mm").parse(Resolved);

Comments

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.