Android get difference in milliseconds between two dates

android, date, java

Solution

Use GregorianCalendar to create the date, and take the diff as you otherwise would.

GregorianCalendar currentDay=new  GregorianCalendar (currentYear,currentMonth,currentDay,currentHour,currentMinute,0);
GregorianCalendar nextDay=new  GregorianCalendar (nextYear,nextMonth,nextDay,nextHour,nextMinute,0);

diff_in_ms=nextDay. getTimeInMillis()-currentDay. getTimeInMillis();

Problem

I have Integer fields: currentYear,currentMonth,currentDay,currentHour,currentMinute and nextYear,nextMonth,nextDay,nextHour,nextMinute. How I can get difference between those two spots in time in milliseconds. I found a way using Date() object, but those functions seems to be depricated, so it's little risky. Any other way?

Original source