Android / Java - Figuring out what the date will be
I'm creating an application that allows the person to select a day within the current week (Days 1/Sunday through 7/Saturday) and see whats on the agenda for that day.
The functionality I'm looking for is to check what today's date is and what day of the week it is. With this information It will show the current weekdays 1 through 7 and I want them to display the date of that day
Example: Today is Thursday 6/23/2011 (Day 5) I can find this information with the following code:
Calendar c = Calendar.getInstance();
int DayOfWeek = c.get(Calendar.DAY_OF_WEEK);
Calendar c = Calendar.getInstance();
int DayOfWeek = c.get(Calendar.DATE);
I'm trying to figure out what functionality or whatever it is to end up with the following result:
Sunday : 6/19/2011, Monday : 6/20/2011, Tuesday : 6/21/2011, We开发者_开发知识库dnesday : 6/22/2011, Thursday : 6/23, 2011, Friday: 6/24/2011, Saturday : 6/25/2011
Select the day of week (as you have above) from the Calendar.
Back off that number of days, which is the "start" day. Then add six days, which will be the "end" day.
Calendar cal = new GregorianCalendar();
int day = cal.get(Calendar.DAY_OF_WEEK);
cal.add(Calendar.DAY_OF_MONTH, -day);
System.out.println(cal.toString());
cal.add(Calendar.DAY_OF_MONTH, 6);
System.out.println(cal.toString();
精彩评论