Skip to content Skip to sidebar Skip to footer

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.

Solution 2:

Refer these links,

Find day of the week

to find the day of the week according to a specific date

try like below,

Calendar calendar=Calendar.getInstance();

calendar.setTime(specific_date);

int weekday = calendar.get(Calendar.DAY_OF_WEEK);

Find the difference between two times

Post a Comment for "Find A Day According To Date In Android"