Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Date wierdness

Reply
Thread Tools

Re: Date wierdness

 
 
Tim Slattery
Guest
Posts: n/a
 
      10-24-2005
Tim Slattery <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Monique Y. Mudama
Guest
Posts: n/a
 
      10-24-2005
On 2005-10-24, Tim Slattery penned:
> Tim Slattery <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-25-2005
On Mon, 24 Oct 2005 14:50:32 -0400, Tim Slattery <(E-Mail Removed)>
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date wierdness Tim Slattery Java 1 10-25-2005 05:12 PM
Cisco 837 and Cisco VPN client wierdness.. any ideas? Christian Hewitt Cisco 1 04-30-2005 11:33 AM
AS5359 IP address Wierdness Jason Cisco 0 04-08-2005 04:49 PM
Datagrid Cell Spacing Wierdness Terry Olsen ASP .Net 2 03-29-2005 01:57 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM



Advertisments