String str = "13/06/2011";
SimpleDateFormat formatter =开发者_如何学C new SimpleDateFormat("dd/MM/yyyy");
Date date = (Date)formatter.parse(str);
I guess that your Date
class is actually a java.sql.Date
.
What does your import statement say? Are you importing some other class (for example java.sql.Date
) by accident? What does the compiler say when you remove the class cast (which should not be there)?
DateFormat.parse()
returns an instance of java.util.Date
and not java.sql.Date
.
In order to convert from java.util.Date
to java.sql.Date
, I do the following:
java.util.Date fromDate = df.parse(fromdate1);
java.sql.Date sqlDate = new java.sql.Date(fromDate.getTime());
精彩评论