Consider the code below. I'm calculating the differences in days between two dates. However, the output is sometimes invalid. Does anyone know how this could be? Don't be concerned about leap years.
SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy")
Date date1 = (Date) myFormat.parse(datenow);
Date date2 = (Date) myFormat.parse(factuurdatumList.get(i));
long difference = date1.getTime() - date2.getTime();
System.out.println("Days: " + TimeUnit.DAYS.convert(difference, TimeUnit.MILLISECONDS));
int openstaand = (int) TimeUnit.DAYS.convert(difference, TimeUnit.MILLISECONDS);