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 convert String to Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "convert String to Date" Watch "convert String to Date" New topic

convert String to Date

meena latha
Ranch Hand

Joined: Jan 24, 2005
Posts: 219

I have written a small program that calculate 30 day
old Date from current date.I want a the date to be formatted in MM/dd/yyyy format.Below code is giving ClassCastException at line 1.Not sure wat is wrong.Please correct me.


[ March 16, 2006: Message edited by: meena latha ]
[ March 16, 2006: Message edited by: meena latha ]
marc weber

Joined: Aug 31, 2004
Posts: 11343

Note that java.sql.Date extends java.util.Date.

In this example, the true type is java.util.Date (as returned by SimpleDateFormat's parse method), but you're trying to downcast to java.sql.Date.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: convert String to Date
It's not a secret anymore!