Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's wrong with my SimpleDateFormat?

 
Bob Backlund
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Ess
Bartender
Pie
Posts: 9264
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic