File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 8708
    
    6

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What's wrong with my SimpleDateFormat?
 
Similar Threads
how to update one column of my table?
Problem with day light savings in Simple Date Formatter
How do i format a string to date
How to compare 2 Dates in String Format
Getting current GMT date as Date object