How do I calculate the date difference?
How to calculate the date difference in A开发者_如何学编程ndroid?
If you can't afford 3rd party libraries like JodaTime, then your best bet is really java.util.Calendar
. You can use the Calendar#add()
method in a loop to calculate the difference in years, months and days between two instances. Then to calculate the difference in hours, minutes and seconds, just do the usual math on Calendar#getTimeInMillis()
.
Long story short, I've posted a basic example before here. You may find it useful.
精彩评论