Tuesday 15 March 2011

calendar - DAY_OF_WEEK always returns 7 in Java GregorianCalendar -



calendar - DAY_OF_WEEK always returns 7 in Java GregorianCalendar -

so want java gregoriancalendar seems going way harder should. want day of week month , date. won't that. know people wrong reply because don't know month numbered 0 while day_of_week numbered 1 (like here , here). that's not problem. problem day_of_week always, always, returns 7, no matter set date to. when convert gregoriancalendar string, day_of_week appears ?, though have set year, month, , dayofmonth.

the code happening:

gregoriancalendar thedate; public observabledate(int year, int month, int dayofmonth, int hourofday, int minute, int second) { thedate = new gregoriancalendar(year, month, dayofmonth, hourofday, minute, second); thedate.setfirstdayofweek(gregoriancalendar.sunday); system.out.println("day_of_week = "+thedate.day_of_week); system.out.println(thedate.tostring()); }

the code calls it:

observabledate thedate = new observabledate(2001, 3, 24, 9, 00, 00);

output:

day_of_week = 7 java.util.gregoriancalendar[time=?,arefieldsset=false,areallfieldsset=false,lenient=true,zone=sun.util.calendar.zoneinfo[id="america/new_york",offset=-18000000,dstsavings=3600000,usedaylight=true,transitions=235,lastrule=java.util.simpletimezone[id=america/new_york,offset=-18000000,dstsavings=3600000,usedaylight=true,startyear=0,startmode=3,startmonth=2,startday=8,startdayofweek=1,starttime=7200000,starttimemode=0,endmode=3,endmonth=10,endday=1,enddayofweek=1,endtime=7200000,endtimemode=0]],firstdayofweek=1,minimaldaysinfirstweek=1,era=?,year=2001,month=3,week_of_year=?,week_of_month=?,day_of_month=24,day_of_year=?,day_of_week=?,day_of_week_in_month=?,am_pm=0,hour=9,hour_of_day=9,minute=0,second=0,millisecond=?,zone_offset=?,dst_offset=?]

any thought why happening?

you accessing field constant instead of getting its' value. believe wanted utilize like,

system.out.println("day_of_week = " + thedate.get(calendar.day_of_week));

java calendar dayofweek gregorian-calendar

No comments:

Post a Comment