Find A Day According To Date In Android
I have 2 questions: How can I find what is the day of the week according to a specific date in JAVA ? I want to find a difference between 2 times (each time include date and hour
Solution 1:
While not particularly great, the standard Java Calendar
class should be sufficient for solving your first problem. You can set the time of a Calendar instance using a Date object, then access the DAY_OF_WEEK field. Something like this:
Datedate=newDate();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
As for the second problem, it depends how you want the difference to be measured. If you just want the difference in milliseconds, you can simply call the getTime()
method on each of your Date instances, and subtract one from the other. If you want it in terms of seconds, minutes, hours, days, etc you can simply do some simple arithmetic using that value.
Post a Comment for "Find A Day According To Date In Android"