Calendar class question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Z.K

    #1

    Calendar class question

    I was wondering if someone could explain something that while not a big
    deal, I would not mind understanding why. When I set the Month field
    with the set command with the value 1 and then use get to read it back,
    it reads it as 0 and not 1.

    Z.K.
  • John W. Kennedy

    #2
    Re: Calendar class question

    Z.K wrote:
    I was wondering if someone could explain something that while not a big
    deal, I would not mind understanding why. When I set the Month field
    with the set command with the value 1 and then use get to read it back,
    it reads it as 0 and not 1.
    This should not be. Please provide a complete example of what you are doing.

    --
    John W. Kennedy
    "The first effect of not believing in God is to believe in anything...."
    -- Emile Cammaerts, "The Laughing Prophet"

    Comment

    • Z.K

      #3
      Re: Calendar class question

      John W. Kennedy wrote:
      Z.K wrote:
      >I was wondering if someone could explain something that while not a
      >big deal, I would not mind understanding why. When I set the Month
      >field with the set command with the value 1 and then use get to read
      >it back, it reads it as 0 and not 1.
      >
      This should not be. Please provide a complete example of what you are
      doing.
      >
      This is the code. I enter a 2 for month and I get 1 using the get command.

      Z.K.

      -------------

      GregorianCalend ar d = new GregorianCalend ar();

      d.set(Calendar. DAY_OF_MONTH,1) ;
      d.set(Calendar. MONTH,2);
      d.set(Calendar. YEAR,2004);
      d.set(Calendar. DAY_OF_YEAR,32) ;

      System.out.prin tf("%d-%d-%d\nDayOfYear =
      %d\n",d.get(Cal endar.MONTH),d. get(Calendar.DA Y_OF_MONTH),d.g et(Calendar.YEA R),d.get(Calend ar.DAY_OF_YEAR) );

      Comment

      • Robert Larsen

        #4
        Re: Calendar class question

        Z.K wrote:
        GregorianCalend ar d = new GregorianCalend ar();
        >
        d.set(Calendar. DAY_OF_MONTH,1) ;
        d.set(Calendar. MONTH,2);
        d.set(Calendar. YEAR,2004);
        d.set(Calendar. DAY_OF_YEAR,32) ;
        >
        Last I checked day 32 of the year was in february so Java does nothing
        wrong.

        Comment

        Working...