Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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 The Software Craftsman this week in the Agile 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
It is sorta covered in the JavaRanch Style Guide.
subject: Date into Calendar? Howto?