I'm trying to calculate the counts of days between two dates. Here is my code:
public class Main {
public static void main(String[] args) {
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
Date date1 = null;
Date date2 = null;
String str1 = "01.01.1900";
String str2 = "16.06.2017";
try{
date1 = format.parse(str1);
date2 = format.parse(str2);
} catch (Exception e){
e.printStackTrace();
}
long i1 = date2.getTime() - date1.getTime();
System.out.println(i1/86400000);//milisec to days
}
}
The result is: 42899 days.
BUT if we recheck that subtraction in EXCEL, the result is 42901
Please, can anybody explain me where is the truth result?