I need to compare two times in java and make sure they are within ten minutes from each other. This would seem simple enough and was simple enough before Date was deprecated. Does anyone have any idea of how the best way to program this in java is? I saw the gregorian calendar but i dont see how to access the fields for minutes or day etc.
Date.getTime() is not deprecated and gives you a long representing milliseconds since the epoch. You can use this as basis for such simple comparisons.
long diffInMins = Math.abs(date1.getTime() - date2.getTime()) / 60000;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With