Sharfi Sharfi - 1 year ago 62
Java Question

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";

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.

Answer Source

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


  • 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download