Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDBC not working right with Calendar object?

Status
Not open for further replies.

carpeliam

Programmer
Mar 17, 2000
990
US
I have the following DATETIME field value in my database (MySQL):
2000-12-09 00:00:00
Let's call the column name "my_date".


In my Java class, I call:
myCalendar = new GregorianCalendar();
myCalendar.setTime (rs.getDate("my_date"));

System.out.println(myCalendar.get(Calendar.MONTH) +"\n" + rs.getDate("my_date"));

I get the following print-out:

2
2001-03-31

Indicating that somewhere the month is being changed from 3 to 2. Does MONTH start with 0? That doesn't seem right, as day and year both print correctly. Why would day or year start at 1 and month start at 0? Liam Morley
lmorley@wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
 
Yes, the month does begin with 0. I am not sure why it is implemented this way but according to the Java API, this value is calendar specific. I don't know which Calendar has a month value beginning with 1 because those that I had use begin with 0 too.

Hope this helps,
Leon
 
Thanks.. I kind of figured this out when I noticed that &lt;CODE&gt;Calendar.JANUARY&lt;/CODE&gt; is equal to 0 ;o)<br><br>Thanks though, I'm just a bit slow :eek:) <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top