Sharfi
Sharfi

Reputation: 365

I am getting an unexpected output of SimpleDateFormat.parse().

When I am executing the following code

    SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/YYYY");

    Date today=new Date();

    String olddate="03/11/2016";
    System.out.println(sdf.parse(olddate));

Why the Result is displaying Sun Dec 27 00:00:00 IST 2015.

However I was expecting Wed Nov 03 00:00:00 IST 2016.

Anyone can please explain. And how can I get the desired output.

Upvotes: 0

Views: 59

Answers (1)

Subhrajyoti Majumder
Subhrajyoti Majumder

Reputation: 41200

Date format is wrong. It should be y instead of Y-

dd/MM/yyyy

  • Y specify Week year
  • y specify Year

For a more detailed insight view, check the link Oracle Docs and you'll see the meaning of each character we pass there.

Upvotes: 5

Related Questions