Re: Date wierdness

Discussion in 'Java' started by Tim Slattery, Oct 24, 2005.

  1. Tim Slattery

    Tim Slattery Guest

    Tim Slattery <> wrote:


    >Why does SimpleDateFormat seem to bump the month up by one??


    Nemmind, I figured it out. gc.get(GregorianCalendar.MONTH) returns a
    zero-based integer from 0 (January) to 11 (December). I assumed a
    one-based integer.

    The documentation doesn't actually say that. It says that it returns
    one of the symbolic constants (Calendar.JANUARY - Calendar.DECEMBER).
    The definitions of those constants only say "Value of the MONTH field
    indicating the nth month of the year" with "nth" replaced by the
    proper ordinal. It never says whats actually being returned!!

    --
    Tim Slattery
    Tim Slattery, Oct 24, 2005
    #1
    1. Advertising

  2. On 2005-10-24, Tim Slattery penned:
    > Tim Slattery <> wrote:
    >
    >
    >>Why does SimpleDateFormat seem to bump the month up by one??

    >
    > Nemmind, I figured it out. gc.get(GregorianCalendar.MONTH) returns a
    > zero-based integer from 0 (January) to 11 (December). I assumed a
    > one-based integer.
    >
    > The documentation doesn't actually say that. It says that it returns
    > one of the symbolic constants (Calendar.JANUARY -
    > Calendar.DECEMBER). The definitions of those constants only say
    > "Value of the MONTH field indicating the nth month of the year" with
    > "nth" replaced by the proper ordinal. It never says whats actually
    > being returned!!
    >


    I had this same problem. And then I did eventually find the
    documentation, but not where I expected it.

    Ahah! In the description of the MONTH field, which if you're anything
    like me, you had absolutely no reason to scrutinize:

    "Field number for get and set indicating the month. This is a
    calendar-specific value. The first month of the year is JANUARY which
    is 0; the last depends on the number of months in a year."

    Because my application actually interacts with a back end that assumes
    January = 1, I actually did some math or something to make sure that I
    could handle arbirary Java values of January. Because I didn't see
    that note.

    --
    monique

    Ask smart questions, get good answers:
    http://www.catb.org/~esr/faqs/smart-questions.html
    Monique Y. Mudama, Oct 25, 2005
    #2
    1. Advertising

  3. Tim Slattery

    Roedy Green Guest

    On Mon, 24 Oct 2005 14:50:32 -0400, Tim Slattery <>
    wrote, quoted or indirectly quoted someone who said :

    >Nemmind, I figured it out. gc.get(GregorianCalendar.MONTH) returns a
    >zero-based integer from 0 (January) to 11 (December). I assumed a
    >one-based integer.


    there are plenty more gotchas awaiting you. See
    http://mindprod.com/jgloss/gotchas.html#DATE
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Oct 25, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Terry Olsen

    Datagrid Cell Spacing Wierdness

    Terry Olsen, Mar 28, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    556
    Terry Olsen
    Mar 29, 2005
  2. danthman

    Wierdness with "Imports" statement

    danthman, Dec 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,182
    danthman
    Dec 16, 2005
  3. Larry
    Replies:
    0
    Views:
    393
    Larry
    Feb 17, 2006
  4. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,251
    Michael Borgwardt
    May 30, 2004
  5. Tim Slattery

    Date wierdness

    Tim Slattery, Oct 24, 2005, in forum: Java
    Replies:
    1
    Views:
    377
    Tim Slattery
    Oct 25, 2005
Loading...

Share This Page