Results 1 to 1 of 1
  1. #1
    tomblue84 is offline Member
    Join Date
    Mar 2010
    Posts
    1
    Rep Power
    0

    Default Calendar days mixed up..

    Hi, I'm new to the forum and I'm building a calendar-based program..
    Having some difficulties with setting the calendar straight, here is my code:


    Java Code:
    GregorianCalendar cal = new GregorianCalendar(year, month, 1);	//setting calendar for the first of that month
                  cal.setFirstDayOfWeek(1);
                    nod = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
                    som = cal.get(GregorianCalendar.DAY_OF_WEEK);
                    
                    System.out.println("------------------------------");
                    System.out.println("Number of days in month: " +nod);
                    System.out.println("First day of month is a (nr): " +som);
                    
                                   
                    //Draw calendar
                    for (int i=1; i<=nod; i++){
                            int row = new Integer((i+som-2)/7);  //(1+2-2)/7= 0.11    = 0
                            int column  =  (i+som-2)%7;			 //(1+2-2)%7= 
                            //System.out.println("Row: " +row);
                            //System.out.println("Column: " +column);
                            mtblCalendar.setValueAt(i, row, column);
                    }
    
                    //Apply renderers
                    tblCalendar.setDefaultRenderer(tblCalendar.getColumnClass(0), new tblCalendarRenderer());
    Now "som" always receives a day ahaid of the first day of the month. Expl: this year in march, the first is on a monday.. What does "som = cal.get(GregorianCalendar.DAY_OF_WEEK);" it gets "2" back. Even though I set the firstday on a monday "cal.setFirstDayOfWeek(1);"

    How come? Can someone get me some clarity in this?

    Thanks alot!


    Edit: solved with work around
    Last edited by tomblue84; 03-18-2010 at 10:36 AM. Reason: solved

Similar Threads

  1. Mixed Fraction
    By x3iancute in forum NetBeans
    Replies: 2
    Last Post: 01-19-2010, 04:15 PM
  2. Mixed Fraction JAVA
    By x3iancute in forum JCreator
    Replies: 0
    Last Post: 01-19-2010, 03:39 PM
  3. swing mixed with awt graphics
    By weddy69 in forum AWT / Swing
    Replies: 2
    Last Post: 08-31-2009, 09:01 AM
  4. Mixed language project?
    By toadaly in forum NetBeans
    Replies: 5
    Last Post: 03-11-2009, 07:29 AM
  5. No fo days between two dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 10:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •