How can I check if 24H has passed since some time using java?
Is their any function or 开发者_开发问答other way to check if 24H has passed since some time variable, using java?
**I need this code to support android
System.getCurrentTimeMillis()
gives you the current time in milliseconds. Check if its value is more than 24 hours greater than the stored value.
I already used a library called joda-time. This library is very usefull when comes the time to manipulate dates, times, intervals, etc. It require some investisment to learn how to use the library, but once its done the code is more expressive.
For example you can calculate interval of time like this:
Days days = Days.daysBetween(start, end);
Hours hours = Hours.hoursBetween(start, end);
You can convert jdk Date to Joda DateTime an vice versa using this code:
// from Joda to JDK
DateTime dt = new DateTime();
Date jdkDate = dt.toDate();
// from JDK to Joda
dt = new DateTime(jdkDate);
It might be overkill for your needs, but I tought it could be good to know that such library exists.
精彩评论