在android中根据日期查找一天

I have 2 questions:

  1. How can I find what is the day of the week according to a specific date in JAVA ?

  2. I want to find a difference between 2 times (each time include date and hour) in Java or PHP, someone can help me with that?

Thanx,

EDIT: I still have a problem with that, I dont success to find the date of a specific date... i'm trying 2 ways, boths are not working.

1.

GregorianCalendar g = new GregorianCalendar(year, month, day, hour, min);
 int dayOfWeek=g.DAY_OF_WEEK;

2.

Calendar cal = Calendar.getInstance();
cal.set(year, month, day, hour, min);           
int dayOfWeek2 = cal.get(Calendar.DAY_OF_WEEK);

Someone cane give me another solution?

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

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:

Date date = new Date();
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.