Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-16-2007, 07:49 PM
orchid's Avatar
Member
 
Join Date: Apr 2007
Location: Midwest
Posts: 60
orchid is on a distinguished road
Gregorian calendar issue
Something is not right with my code.

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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-16-2007, 07:51 PM
Member
 
Join Date: Apr 2007
Location: USA
Posts: 50
derrickD is on a distinguished road
The months are zero indexed (who knows why.....!!!)
Best to use the Calendar constants rather than rely on int literals; e.g., Calendar.SEPTEMBER.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Try Catch issue curtis_fraser Advanced Java 2 12-14-2007 12:04 AM
Issue chaitu444 New To Java 2 11-06-2007 08:49 PM
Alignment Issue... chanduseec JavaServer Faces 0 08-13-2007 02:04 PM
Help with gregorian calendar osval New To Java 2 08-07-2007 12:21 AM
compilation issue orchid Eclipse 2 04-20-2007 01:51 AM


All times are GMT +3. The time now is 03:41 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org