« Don't use YYYY in your date format template 10 Apr 2015
yyyy is the pattern string to identify the year in the SimpleDateFormat class.
Java 7 introduced YYYY as a new date pattern to identify the date week year.
An average year is exactly 52.1775 weeks long, which means that eventually a year might have either 52 or 53 weeks considering indivisible weeks.
Using YYYY unintendedly while formatting a date can cause severe issues in your Java application.
As an example:
The snippet above prints “And the year is… 2015”, because 2015 week year started on 29/12/2014.
This issue seemed to be the root cause of the massive outage that Twitter suffered last year.
So double check if you really need to use YYYY while formatting your date, and in case of doubt… Better call Saul!!
« Home