How to get year, month, day seperately from a Date type data?

How to get year, month, day seperately from a Date type data?

exmaple:

Date today=new Date();

the value oftodayis 2007-05-09, I want to get the year,month, day seperately. how to do that?

PS: the method getDay(), getMonth(), getYear () are deprecated. I can not use these methods.

Message was edited by:

Mellon

[371 byte] By [Mellona] at [2007-11-27 3:50:41]
# 1
Hi,Take a look at the Calendar class. http://java.sun.com/javase/6/docs/api/java/util/Calendar.htmlKaj
kajbja at 2007-7-12 8:54:37 > top of Java-index,Java Essentials,Java Programming...
# 2
String s = today.toString();StringTokenizer st = new StringTokenizer(s, "-");String year = st.nextToken();String month = st.nextToken();String day = st.nextToken();You can use Integer.parseInt() to get numeric values.
baldmountaina at 2007-7-12 8:54:37 > top of Java-index,Java Essentials,Java Programming...
# 3

> String s = today.toString();

> StringTokenizer st = new StringTokenizer(s, "-");

> String year = st.nextToken();

> String month = st.nextToken();

> String day = st.nextToken();

>

> You can use Integer.parseInt() to get numeric values.

A bad advice. That won't work in locales where the date is printed as e.g. year/month/day

You should use the Calendar class.

Kaj

kajbja at 2007-7-12 8:54:37 > top of Java-index,Java Essentials,Java Programming...