Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

java.sql.Date to java.util.Calendar

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All
I have a date field in my database, which I retrieve. This has to be converted to Calendar type before I present. Can anyone suggest a way to do this. The Calendar.setTime(Date)does not serve my purpose.
Thanks
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Construct the proper calendar class with the date you retrieve, apu thinks (make an object, then use). The calendar class deprecates the date class (object itself), methinks.
Smack apu upside head iffin he wrong.
Better answer when Apu has JDK in front of him.
Better answer tomorrow......
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srividya Shiv:
The Calendar.setTime(Date)does not serve my purpose.


This statement confuses me, this is how the API's intend for this operation to occur. The code to do this is

Calendar c = new GregorianCalendar();
c.setTime(dateIn);
c.get(Calendar.YEAR);

This assumes that dateIn is of type java.sql.Date. This will reassign the values of the Calendar refernce to the Gregorian Calendar Object to the dateIn. Note, to assure all the fields in the GregorianCalendar object represent your date, it is necessary to call a get() on the object (This is a bug IMHO but, it's how the GregorianCalendar works so...)
I hope this helps
 
reply
    Bookmark Topic Watch Topic
  • New Topic