| Author |
java.sql.Date issue
|
Greg Reeder
Ranch Hand
Joined: Jun 14, 2011
Posts: 99
|
|
Hi,
I have an issue that I cannot understand. Today is the 24th of June, 2011. Here is my code:
as expected, both DAY_OF_MONTH and DATE return the same integer. However, it returns the WRONG integer. It returns 5??? I do not understand this at all. Any ideas?
I post this here as I am about to create an SQL date, but I guess I am still in the wrong section. I dont know where else to post it.
Thanks
Greg
|
 |
joy b chakravarty
Ranch Hand
Joined: May 16, 2011
Posts: 62
|
|
Please read the API.. use the get and set
DAY_OF_MONTH
public static final int DAY_OF_MONTH
Field number for get and set indicating the day of the month. This is a synonym for DATE. The first day of the month has value 1.
Checking the source code i found this
public final static int DAY_OF_MONTH = 5;
http://www.docjar.com/html/api/java/util/Calendar.java.html
you are accessing Calendars static DAY_OF_MONTH instead of your objects DAY_OF_MONTH, which gets created using Calendar.getInstance();
|
Cheers, Joy [SCJP 1.4, SCBCD 5.0]
get high on alcohol, algorithm or both
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
What you are seeing isn't something from your Calendar object. It's a static variable Calendar.DATE which is an arbitrary constant which you use to say "Gimme the day of the month"... like this...
(By the way, why is this a question about java.sql.Date?)
|
 |
Greg Reeder
Ranch Hand
Joined: Jun 14, 2011
Posts: 99
|
|
|
That seems to work now! Thank you, very much. I posted this question here because my end goal is an sql.Date which the user is selecting that I am putting into an SQLite3 database. I just did not know any better place to post it. Thank, very much.
|
 |
Greg Reeder
Ranch Hand
Joined: Jun 14, 2011
Posts: 99
|
|
|
( if I posted the rest of the code, it would show me making the sql date, but you are correct, this should have been called Calendar issue)
|
 |
 |
|
|
subject: java.sql.Date issue
|
|
|