Reputation: 780
So, i found the java.util.Calendar, and tried to use it for a android project i'm working on.
I do not understand at all how Calendar.DAY_OF_WEEK can return 7, when it's Thursday? And now when it's August Calendar.WEEK_OF_YEAR returns 4, which doesn't make any sense at all!
I have tried GregorianCalendar too, and it gives exactly the same results.
Tried to find any documentation about how they count, but i can't find anything. Seems like there is something very obvious, but which i just cannot find out what it is!
The code i wrote is here:
// Get if daily or weekly
boolean daily;
daily = getPrefs.getBoolean("checkbox_daily", false);
String day = "0";
if (daily){
switch(GregorianCalendar.DAY_OF_WEEK){
case GregorianCalendar.MONDAY:
Do_stuff();
break;
case GregorianCalendar.TUESDAY:
Do_stuff();
break;
case GregorianCalendar.WEDNESDAY:
Do_stuff();
break;
case GregorianCalendar.THURSDAY:
Do_stuff();
break;
case GregorianCalendar.FRIDAY:
Do_stuff();
break;
}
}
Upvotes: 0
Views: 184
Reputation: 4029
From java.util.Calendar docs:
Calendar defines a locale-specific seven day week using two parameters: the first day of the week and the minimal days in first week (from 1 to 7). These numbers are taken from the locale resource data when a Calendar is constructed. They may also be specified explicitly through the methods for setting their values.
When setting or getting the WEEK_OF_MONTH or WEEK_OF_YEAR fields, Calendar must determine the first week of the month or year as a reference point. The first week of a month or year is defined as the earliest seven day period beginning on getFirstDayOfWeek() and containing at least getMinimalDaysInFirstWeek() days of that month or year. Weeks numbered ..., -1, 0 precede the first week; weeks numbered 2, 3,... follow it. Note that the normalized numbering returned by get() may be different. For example, a specific Calendar subclass may designate the week before week 1 of a year as week n of the previous year.
Upvotes: 1
Reputation: 240996
GregorianCalendar.DAY_OF_WEEK
is constant,
you need calendarInstance.get(GregorianCalendar.DAY_OF_WEEK);
Upvotes: 8