Link to home
Start Free TrialLog in
Avatar of theartha
thearthaFlag for United States of America

asked on

Cannot format given object as date

Hi There,

I am retrieving a value from database
2010-07-02 00:00:00.0 as json object and I am trying to convert it into Java Date using
SimpleDateFormat dateFormat = new SimpleDateFormat("MMddyy");

dateFormat .format(ja1.get(8);

I received the below error.
"Cannot format given object as date "

any clues?

Thanks!

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

What about the following?
dateFormat .format(ja1.get(8).toString());

Open in new window

Avatar of theartha

ASKER

CEHJ: Same error.

"Cannot format given object as date"
database column type is dateTime
Please post output of both of the following:
System.out.println(ja1.get(8).getClass());


System.out.println(ja1.get(8).toString());

Open in new window

class java.lang.String
2010-07-02 00:00:00.0
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just to change 2010-07-02 00:00:00.0 to 070210
:)
try,

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = dateFormat.parse( ja1 ) ;