Solved

Cannot format given object as date

Posted on 2010-11-08
9
823 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

770 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