Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO GET THE YEAR IN A DATE OBJECT??

Status
Not open for further replies.

Inandjo

Programmer
Dec 7, 2001
46
FR
hi,

i have an date object "birthday".
How can i get the year on that object , since getYear() method is deprecated.
Thanx

La faim justifie les moyens!
 
You can get the year by using the get() method of calendar :
Code:
Date date = null;
DateFormat myDate = new SimpleDateFormat("yyyy-MM-dd");
try {
  date = myDate.parse("2003-08-20");
} catch (ParseException e) {
}
System.out.println("Date = " + date);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
System.out.println("year = " + calendar.get(Calendar.YEAR));
 
thanx dude,

i wasn't carefull enough about the calendar functions list.
:<

Thanx!!

La faim justifie les moyens!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top