tamtom tamtom - 5 months ago 21
Java Question

get number of the week in the year where first day of the week is Sunday

I'm trying to get the number of the week for a date , In my country the week begins on Sunday so the week number of 6/5/2016 is 23 but it returning 22 because the ISO week in JAVA starts from Monday , I have used the following methods but it's not working

mCalendar = Calendar.getInstance();
int weekNum = mCalendar.get(Calendar.WEEK_OF_YEAR); //returns 22 I need 23
// I have tried the following method but it has no effect
mCalendar.setFirstDayOfWeek(Calendar.SUNDAY);


note that I can't use the Time Class I can only use Java 7

Answer

I've just figured out how to change it you need to set up two things 1-first day of the week 2-the minimal day of week

setFirstDayOfWeek(Calendar.SUNDAY);    
setMinimalDaysInFirstWeek(7);

this will tell the calendar to make the fist day is sunday and with 7 days minimal week