• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5799
  • Last Modified:

Java:Cannot format given Object as a Date

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
coolgem
Asked:
coolgem
  • 3
  • 2
2 Solutions
 
coolgemAuthor Commented:
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
 
InteractiveMindCommented:
Can you provide a Date object instead of a String object, to your method?
0
 
InteractiveMindCommented:
If not, then will the data within the String be in a particular format?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
coolgemAuthor Commented:
NO.  Because after the sql execution the field is in a string.
0
 
InteractiveMindCommented:
[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
 
AutogardCommented:
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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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