Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 873
  • Last Modified:

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!

0
theartha
Asked:
theartha
  • 4
  • 4
1 Solution
 
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
 
thearthaAuthor Commented:
database column type is dateTime
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
CEHJCommented:
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
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now