File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes What's wrong with my SimpleDateFormat? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What Watch "What New topic

What's wrong with my SimpleDateFormat?

Bob Backlund
Ranch Hand

Joined: Jun 05, 2003
Posts: 51
Hi I'm trying to convert a date/time field in a SQL database to a more simple date format using:
DateFormat df = new SimpleDateFormat("EEE, MMM d yyyy" );
String stringDate = df.format(stringDate);
this is displayed using a simple String but the date is still being displayed in it's original date/time format, and I keep getting the following error:
java.lang.IllegalArgumentException: Cannot format given Object as a Date
This is becoming very frustrating.

Joe Ess

Joined: Oct 29, 2001
Posts: 9189

DateFormat either converts java.util.Date to a String via the format() method or the other way around with the parse() method. It doesn't do String to String or java.sql.Date to anything formatting. You could create one format to parse the database string into a Date and then use another format to convert that Date into the String format you desire.
[ October 29, 2003: Message edited by: Joe Ess ]

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: What's wrong with my SimpleDateFormat?
It's not a secret anymore!