It must be
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd);
instead of
DateFormat formatter = new SimpleDateFormat("YYYY-MM-DD");
in SimpleDateFormat "Y" is a Unknown pattern character. So don't use it and otherwise you will get IllegalArgumentException.