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]

> 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