-2

Possible Duplicate:
Date object to Calendar [Java]

I have a Java Date object like

     Date A = Mon Nov 07 00:00:00 CET 2011;

I want to get the year ,month and day. But i saw like these getYear ,getMonth and getDay is deprecated. So how can i extract the above from the above date object.

Community
  • 1
  • 1
saurabh ranu
  • 1,351
  • 6
  • 18
  • 24
  • 1
    Try searching for identical questions before posting! http://stackoverflow.com/questions/2727698/date-object-to-calendar-java – vaughandroid Nov 16 '11 at 14:12

4 Answers4

2

You can use Calendar.setTime().

Mansoor Siddiqui
  • 20,853
  • 10
  • 48
  • 67
2

Try the following:

Date a = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(a);
Scott
  • 9,458
  • 7
  • 54
  • 81
2

try something like this:

    Date d = new Date();
    Calendar c = Calendar.getInstance();
    c.setTime(d);
Kai Woska
  • 81
  • 8
2
Calendar c = new GregorianCalendar();
c.setTime(new Date());
int year = c.get(Calendar.YEAR);
Chris
  • 22,923
  • 4
  • 56
  • 50