The code you provided works fine - although the fact that you are claiming that you will have a 4-digit year, a 2-digit month, and then a 2-digit day, and then providing 2-1-1 is pretty cool.
Given the exception you get, I suspect that your template is actually "YYYY.MM.dd" . This is true in Java 7 , where Y means "week year", but it is not valid in Java 6 , which does not support Y as a format specifier - only Y
Even when it really is, you really do not want Y here - you will indicate only weekly years, when you will also indicate the week of the week and the day of the week that you are not doing here.
Stick to the template that you really received in the code you sent, but make sure your data really matches it ...
Jon skeet
source share