I have a class where I need to keep track of 7 date objects, one for each day of the week that holds a time.
I set up a calendar like this and assign it to a Date object
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY,0);
cal.set(Calendar.MINUTE,30);
cal.set(Calendar.SECOND,0);
cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
Date FridayOpen = cal.getTime();
Log.i("Creation Day", String.valueOf(FridayOpen.toString()));
Log.i("Creation Day2", String.valueOf(FridayOpen.getDay()));
And the LogCat results are
Creation Day = Fri Dec 07 00:30:00 CST 2012
Creation Day2 = 5
WHY IS IT RETURNING 5 when Friday is clearly day 6 and stored in my Date Object? I can’t switch Calendar.DAY_OF_WEEK when the date is off. I’ve spent hours on this stupid problem.
Because days are from 0 to 6 .
0 for Sunday and 6 for Saturday.
Edit
getDay()Method is Deprecated useCalendar.get(Calendar.DAY_OF_WEEK).