I’m getting the error
java.lang.ClassCastException: java.util.Date
at avb.Test.main(Test.java:38)
SimpleDateFormat(“yyyy-MM-dd HH:mm:ss.SSS”)
from the code
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String tmp = "2012-03-16 18:58:14.0";
Date MaxCmTimerUpdate = (Date)df.parse(tmp);
What am I doing wrong? How do I fix it?
My guess is that you’ve got an import for
java.sql.Date(or some otherDatetype), whereasSimpleDateFormatparses to ajava.util.Date. You shouldn’t need the cast at all.You won’t be able to cast to a different
Datetype – if you need to create ajava.sql.Date, you’ll have to create a new one based on thejava.util.Date, e.g.