I saw all the post in here and still I can\'t figure how do get difference between two android dates.
This is what I do:
long diff = date1.getTime()
If you use Kotlin language for Android development, you can use ExperimentalTime
extension. To get difference in days you can use it like this:
@ExperimentalTime
fun daysDiff(c1: Calendar, c2: Calendar): Double {
val diffInMillis = c1.timeInMillis - c2.timeInMillis
return diffInMillis.milliseconds.inDays
}
or if you want to get results as integer:
@ExperimentalTime
fun daysDiff2(c1: Calendar, c2: Calendar): Int {
val diffInMillis = c1.timeInMillis - c2.timeInMillis
return diffInMillis.milliseconds.toInt(DurationUnit.DAYS)
}