Reputation: 265
I'm getting unexpected output when running following code,
DateFormat df = new SimpleDateFormat("YYYY-MM-dd");
Date date = df.parse("2012-06-23");
System.out.println(df.format(date));
Output : 2012-01-01
I'm expecting 2012-06-23 as output,what am i doing wrong ?
Upvotes: 0
Views: 292
Reputation: 20830
Refer this Date & time in Java. You'll get the date format used
Use 'y' instead of 'Y'.
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date date = df.parse("2012-06-23");
System.out.println(df.format(date));
Upvotes: 3
Reputation: 23301
yyyy should be all lowercase, try that and see if it makes a difference...
Upvotes: 5