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!

thearthaAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
You're passing a String to format. You only pass String to parse - to turn a String into a Date. What is your intention? If it's to change the format, you need to parse first
0
 
CEHJCommented:
What about the following?
dateFormat .format(ja1.get(8).toString());

Open in new window

0
 
thearthaAuthor Commented:
CEHJ: Same error.

"Cannot format given object as date"
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
thearthaAuthor Commented:
database column type is dateTime
0
 
CEHJCommented:
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

0
 
thearthaAuthor Commented:
class java.lang.String
2010-07-02 00:00:00.0
0
 
thearthaAuthor Commented:
Just to change 2010-07-02 00:00:00.0 to 070210
0
 
CEHJCommented:
:)
0
 
ksivananthCommented:
try,

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = dateFormat.parse( ja1 ) ;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.