Have next function to get week of year:
static public Integer getWeek(Date date) {
Calendar cal = Calendar.getInstance();
cal.setMinimalDaysInFirstWeek(1);
cal.setTime(date);
Integer week = cal.WEEK_OF_YEAR;
Integer month = cal.MONTH;
if ((week == 1) && (month == 12)) week = 52;
return week;
}
Call the function with date=02.01.2013
What I see in debug:
- date = Wed Jan 02 00:00:00 SAMT 2013
- week = 3
- month = 2
I want to get: week=1, month=1. Right?
Where am I wrong?
JRE 1.6
Thanks a lot for advance.
Calendar.WEEK_OF_YEARandCalendar.MONTHare static constants Calendar uses to look up fields. You wantAlso, note that (I think) January is considered month 0.