java.text.ParseException: Unparseable date: “2021-06-24“

String to date:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
String nowDate = new SimpleDateFormat("yyyy-mm-dd").format(new Date());

Format must be written, otherwise an error will be reported. Conversion exception: Java. Text. Parseexception: unparseable date

Date subtraction calculation days reference:

int dayNum = (int) ((d2.getTime() - d1.getTime())/(1000 * 3600 * 24));

Read More: