The following code:
Calendar now = Calendar.getInstance();
month = now.get(Calendar.MONTH) + 1;
year = now.get(Calendar.YEAR);
System.out.println(\"Month \"
The documentation differs from the implementation. The supported characters are defined in a string constant in SimpleDateFormat up to API level 23. From the source code:
static final String PATTERN_CHARS = "GyMdkHmsSEDFwWahKzZLc";
Since 'Y' (Week Year) is not included, the pattern validation throws the exception:
java.lang.IllegalArgumentException: Unknown pattern character 'Y'
A quick fix, when week year behaviour isn't required, is to use the 'y', e.g.: yyyy-MM-dd.
'Y' as a pattern character is supported as of API level 24.
The documentation now lists the supported API levels for pattern characters.