Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Calendar.MONTH return wrong value

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Calendar.MONTH return wrong value

    Calendar eCal = Calendar.getInstance();
          eCal.set(2011, 10, 1);
          int iEday= eCal.getActualMaximum(Calendar.DAY_OF_MONTH);
     
     
    System.out.println(eCal.toString()); //  this line print out: java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Singapore",offset=28800000,dstSavings=0,useDaylight=false,transitions=9,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=10,WEEK_OF_YEAR=45,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=309,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=8,HOUR_OF_DAY=20,MINUTE=50,SECOND=31,MILLISECOND=151,ZONE_OFFSET=28800000,DST_OFFSET=0]
     
     
    System.out.println(eCal.MONTH); // this line print out:  2

    what am actually trying to do is to based on the date enter by the user... i will find the maximum date based on the input... but i am now using some test value to try out the function first... Basically what i want to ask is that why eCal.MONTH return a 2 instead of 10 since the month is 10..


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Calendar.MONTH return wrong value

    Read the API doc for the Calendar class and look at the definition of the MONTH variable.
    It is a constant used by methods (look at the get() method) in the class to tell the method what field to look at.

Similar Threads

  1. How much per a month?
    By benglish in forum Totally Off Topic
    Replies: 14
    Last Post: September 23rd, 2013, 04:52 PM
  2. Return Object does not return the expected output
    By Nour Damer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 13th, 2011, 07:24 AM
  3. getTimeInMillis() from the Calendar class returns wrong values
    By 16mydream in forum Java Theory & Questions
    Replies: 2
    Last Post: February 16th, 2011, 01:29 PM
  4. what is wrong with my return statement??????
    By amr in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 13th, 2010, 07:55 PM
  5. Tip of the Month
    By helloworld922 in forum The Cafe
    Replies: 6
    Last Post: July 5th, 2010, 02:42 AM