Solved

Java:Cannot format given Object as a Date

Posted on 2006-06-09
6
5,310 Views
Last Modified: 2008-01-09
I tried this and:
public void setRec_date(String string) {
                                    
            recDate = (String)dateFormat.format(string);
      }
When I run the program the error is : Cannot format given Object as a Date

Thank you
0
Comment
Question by:coolgem
  • 3
  • 2
6 Comments
 

Author Comment

by:coolgem
ID: 16873293
also I defined as a class var :
private SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy");
      
public void setRec_date(String string) {
                             
          recDate = (String)dateFormat.format(string);
     }
When I run the program the error is : Cannot format given Object as a Date

Thank you
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16873433
Can you provide a Date object instead of a String object, to your method?
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16873453
If not, then will the data within the String be in a particular format?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 

Author Comment

by:coolgem
ID: 16873457
NO.  Because after the sql execution the field is in a string.
0
 
LVL 25

Assisted Solution

by:InteractiveMind
InteractiveMind earned 125 total points
ID: 16873478
[Are the sql fields data/times themself? If so, then you can retrieve them as Date objects using either getDate() or (Date)getTimestamp() in the ResultSet class.]
0
 
LVL 8

Accepted Solution

by:
Autogard earned 125 total points
ID: 16875346
Coolgem -- did you try my suggestions in your previous question? (http://www.experts-exchange.com/Programming/Q_21878474.html#16858007) What datatype are your dates stored as in the database?
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …

860 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