i am pretty new to coding, so this might be a stupid question, but I can't find any solution. I want to calculate the difference (in days) between to dates. It works most of the time, but when the month changes, I get weird solutions.
First example:
today - 30 September 2018 = 78 Days,
today - 31 September 2018 = 79 Days (??),
today - 1 October 2018 = 80 Days
Second example:
today - 31 August 2018 = 49 Days,
today - 1 September 2018 = 49 Days
The code
private static int[] abstandTage(GregorianCalendar date1, ArrayList<GregorianCalendar> csvDate)
{
int[] abstand = new int[csvDate.size()];
int i = 0;
while ( i < csvDate.size() )
{
long diffInMillis = csvDate.get(i).getTimeInMillis() - date1.getTimeInMillis();
long tage = diffInMillis / 1000 / 60 / 60 / 24;
abstand[i] = (int) tage;
i++ ;
}
return abstand;
}
date1 is a predefined Date, csvDate is a list with dates. Can anybody help me?
Thanks in advance Alex