Results 1 to 2 of 2
  1. #1
    orchid's Avatar
    orchid is offline Member
    Join Date
    Apr 2007
    Location
    Midwest
    Posts
    60
    Rep Power
    0

    Default Gregorian calendar issue

    Something is not right with my code.

    Java Code:
    ArrayList<DayEntry> month = new ArrayList<DayEntry>();
    
    int now_month = 9;
     
    while(days.hasNext()) {
        Map<String,Object> row = days.next();
        Date in = (Date) row.get(DayType.DATE);
        GregorianCalendar date = new GregorianCalendar();
        date.setTime(in);
        if(date.get(Calendar.MONTH) == now_month) {
            String entry = (String) row.get(DayType.ENTRY);
            month.add(new DayEntry(entry,date));
        }
    }
    I first thought there was something up with my previous code regarding the days iterator, but on close inspection it appears there is something up with the GregorianCalendar...

    System.out.println(in) prints ....
    Wed Sep 27 15:09:58 GMT 2006

    System.out.println(date.getTime()) prints .....
    Wed Sep 27 15:09:58 GMT 2006

    BUT, System.out.println(date.get(Calendar.MONTH)) print ....
    8
    and i am pretty sure Sep is the 9th month of the year.
    Thanks

  2. #2
    derrickD is offline Member
    Join Date
    Apr 2007
    Location
    USA
    Posts
    50
    Rep Power
    0

    Default

    The months are zero indexed (who knows why.....!!!)
    Best to use the Calendar constants rather than rely on int literals; e.g., Calendar.SEPTEMBER.

Similar Threads

  1. Alignment Issue...
    By chanduseec in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 09-30-2008, 06:47 AM
  2. Try Catch issue
    By curtis_fraser in forum Advanced Java
    Replies: 2
    Last Post: 12-13-2007, 11:04 PM
  3. Issue
    By chaitu444 in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 07:49 PM
  4. Help with gregorian calendar
    By osval in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 11:21 PM
  5. compilation issue
    By orchid in forum Eclipse
    Replies: 2
    Last Post: 04-20-2007, 12:51 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
  •