Solved

Cannot format given object as date

Posted on 2010-11-08
9
829 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
ID: 34084321
What about the following?
dateFormat .format(ja1.get(8).toString());

Open in new window

0
 

Author Comment

by:theartha
ID: 34084373
CEHJ: Same error.

"Cannot format given object as date"
0
 

Author Comment

by:theartha
ID: 34084444
database column type is dateTime
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:CEHJ
ID: 34084465
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
 

Author Comment

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

Accepted Solution

by:
CEHJ earned 500 total points
ID: 34084550
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
ID: 34084618
Just to change 2010-07-02 00:00:00.0 to 070210
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34084696
:)
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 34084718
try,

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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

840 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