This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Date into Calendar? Howto? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date into Calendar? Howto?" Watch "Date into Calendar? Howto?" New topic

Date into Calendar? Howto?

wessel zaalberg

Joined: Jul 27, 2001
Posts: 26
I have a query which returns date fields.
I also have a function that returns the number of days between two given Calendars. My problem is how to get the value of a date into a Calendar.
java.util.Date bdat = rs.getDate("bdat_ao");
bdat_ao = Calendar.getInstance();
bdat_ao.set(Calendar.YEAR, bdat.getYear());
I get the warning that bdat.getYear() is deprecated, which I knew but there doesnot seem to be any other way.
Does anybody knows a way around this?
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Wessel,
Look into the java.util.Calendar class. It has superseded the Date stuff:
java.util.Date bdat = rs.getDate( "bdat_ao" );
Calendar cal = new Calendar();
cal.setTime( bdat );
wessel zaalberg

Joined: Jul 27, 2001
Posts: 26
There is indeed a certain logic to it, although not obvious
I agree. Here's the link:
subject: Date into Calendar? Howto?
It's not a secret anymore!