Solved

Java:Cannot format given Object as a Date

Posted on 2006-06-09
6
5,540 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Simple Linear Regression

626 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