URGENT!!!! FORMATTING DATE (HELP!!!! PLSSSS)

hi suppose I import the
java.sql.Date

how can i format the date into this kind like…
Jan 30, 1985
without converting it to string???
so that when you excute this code
System.out.println(sqldate.toString()); the resulting is
(the date today in the format like the above???

THANKS A LOT!!!

http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

Hi ERIK

i appreciated ur reply but i already tried that SimpleDateFormat but again the resulting datatype is not a type of Date but a type of String and I need something to format todays date into this form like
Jan 30, 1985 which in Date datatype instead of String…

Thanks for the one who can help me :wink:

SimpleDateFormat has a method:

parse(String text, ParsePosition pos), returns Date.

Parses text from a string to produce a Date.

Is that what you want?

Hi Malokhan

I tried it already but I don’t know why it always produces this kind of type like these:

Tue May 5 00:00:00 2005 GMT+08+00 something like this

I mean It always produces this kind of output although i used this:

SimpleDateFormat s = new SimpleDateFormat(“MMM dd, yyyy”);
s.parse(datetoday.toString(), parse…);

I need an output like:
May 5, 2005 in Date dataype

THANK YOU

You want to format a Date, but the output should NOT be a String? Why ???
In the example of what you want, you convert a Date to a String too, so why is SimpleDateFormat not any good?
Remember “Jan 30, 1985” is essentially a String which happens to be representing a Date, but a Date object is not a String.

Basically what you want is not possible. The output of Date.toString() is a String in the format you described. Look at the source of java.util.Date, it uses a SimpleDateFormatter too with the format like you described hardcoded.
Maybe you could create your own “MyDate” class, extending the existing Date class, overriding the toString() method to have it behave like you want. Note that java.sql.Date also is a class extending java.util.Date.

OK

I thank you for your advice