Connecting Tech Pros Worldwide Forums | Help | Site Map

Converting Date Object to Calendar Object

Member
 
Join Date: Apr 2008
Location: Philippines
Posts: 35
#1: Oct 13 '09
I'm working on a wicket project, and I'm kinda stumped here on trying to get the components of the date. Thing is, I don't want to use deprecated code, so I decided on using Calendar instead.

For instance I have the following code:

Expand|Select|Wrap|Line Numbers
  1. Date d = (Date) dateModel.getObject(); //generic Date.
  2. ...
  3. Calendar cal = Calendar.getInstance();
  4. ...
  5. System.out.println(" " + month + " " + day + " " + year);
How do I convert it to Calendar so I could just use something like this?

Expand|Select|Wrap|Line Numbers
  1. year = cal.YEAR;
  2. month = cal.MONTH;
  3. ...
kind regards
JR

myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168
#2: Oct 13 '09

re: Converting Date Object to Calendar Object


See Calendar's setTime and setTimeInMillis methods http://java.sun.com/javase/6/docs/api/

Regards,
Alex.
Reply