I am using SimpleDateFormat("dd-MMM-YYYY") in my code, which is giving wrong output.
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-YYYY");
System.out.println("Actual date : "+new Date()+" after Formatting : "+ dateFormat.format(new Date()));
above code is giving : Actual date : Tue Dec 30 13:51:06 IST 2014 after Formatting : 30-Dec-2015
Above code is print date having Year as 1 year ahead. and this issue is replicable for 28-31 december 2014 dates only.
Thanks in advance. --Ajay
You're using YYYY
, which is the "ISO-8601 week year". That should almost always be used in conjunction with w
, "week in year". You want yyyy
to show the normal calendar year.
The reason they're different is that the first ISO-8601 week of a year is the first (Monday to Sunday) week that includes at least 4 days. This means that the first week of the year is the one containing the first Thursday. As January 1st 2015 falls on a Thursday, that means that the week of 2014-12-29 to 2015-01-04 is all "week year 2015, week of year 1". (I'm surprised if you see if for December 28th...)
In other years, the first few days of the year are in week 52 or 53 of the previous year. For example, January 1st 2010 was in week 53 of week-year 2009, and January 1st 2011 was in week 52 of week-year 2010.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With