Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleDateFormat parse does not work properly

Tags:

java

This is probably a very simple question but I dont see the problem or how to resolve it. Thank you for you help.

String date = "04/11/1972"
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/YYYY");
System.out.println(sdf.format(sdf.parse(date));

and it displays : 03/01/1972

Why? How to get back my date. it seems there is a problem with the parse which does not give the proper Date object

Thank you

like image 771
mlwacosmos Avatar asked Jun 01 '12 07:06

mlwacosmos


1 Answers

It is yyyy not YYYY for the year field. That may be the problem! So try this:

String date = "04/11/1972";
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(sdf.format(sdf.parse(date)));
like image 86
Tobias Avatar answered Oct 21 '22 10:10

Tobias