wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What Watch "What New topic
Author

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.
KPS


Cheers!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

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 ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: What's wrong with my SimpleDateFormat?
 
Similar Threads
How to compare 2 Dates in String Format
how to update one column of my table?
How do i format a string to date
Getting current GMT date as Date object
Problem with day light savings in Simple Date Formatter