Solved

Cannot format given object as date

Posted on 2010-11-08
9
812 Views
Last Modified: 2012-05-10
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!

0
Comment
Question by:theartha
  • 4
  • 4
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
What about the following?
dateFormat .format(ja1.get(8).toString());

Open in new window

0
 

Author Comment

by:theartha
Comment Utility
CEHJ: Same error.

"Cannot format given object as date"
0
 

Author Comment

by:theartha
Comment Utility
database column type is dateTime
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:theartha
Comment Utility
class java.lang.String
2010-07-02 00:00:00.0
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
Comment Utility
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
 

Author Comment

by:theartha
Comment Utility
Just to change 2010-07-02 00:00:00.0 to 070210
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:)
0
 
LVL 26

Expert Comment

by:ksivananth
Comment Utility
try,

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now