Monday as first day of the week not sunday  
Author Message
sunspot





PostPosted: 2005-5-19 23:11:00 Top

java-programmer, Monday as first day of the week not sunday hey,

I'm having trouble to tell JAVA that monday is the first day of the week and
not sunday. This is what I have at the moment

Calendar time;
time = Calendar.getInstance();
time.setFirstDayOfWeek(Calendar.MONDAY);


when I output time.get(Calendar.DAY_OF_WEEK) it always gives me a number on
higher then it actually is since it assumes Sunday is day 1. This really is
a annoying bug in my program. Can anyone help me or set me on the right
track ?

thnx in advance


 
Thomas Schodt





PostPosted: 2005-5-19 23:43:00 Top

java-programmer >> Monday as first day of the week not sunday sunspot wrote:

> when I output time.get(Calendar.DAY_OF_WEEK) it always gives me a number one
> higher then it actually is since it assumes Sunday is day 1. This really is
> a annoying bug in my program. Can anyone help me or set me on the right
> track ?

Please don't multi-post.


What do you think the numbers mean?

int j,i = time.get(Calendar.DAY_OF_WEEK);
String s;
switch(i) { // unadjusted; Mon is 2, ..., Sat is 7, Sun is 1
case Calendar.MONDAY: s="Monday";break;
case Calendar.TUESDAY: s="Tuesday";break;
case Calendar.WEDNESDAY: s="Wednesday";break;
case Calendar.THURSDAY: s="Thursday";break;
case Calendar.FRIDAY: s="Friday";break;
case Calendar.SATDAY: s="Satday";break;
case Calendar.SUNDAY: s="Sunday";break;
default: throw new RunTimeException();
}
System.out.println(s);

j = ((i+5)%7)+1; // << adjust so Mon is 1, ..., Sat is 6, Sun is 7
System.out.println(j);
j = (i+6)%7; // << adjust so Mon is 1, ..., Sat is 6, Sun is 0
System.out.println(j);
j = (i+5)%7; // << adjust so Mon is 0, ..., Sat is 5, Sun is 6
System.out.println(j);