0

I success to get my date from JDateChooser into a string with this line:

String d1  = ((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText();

I want to know if there is any method to get a date from a JDateChooser ?

I tried to convert this string into a date , and i have an error in the third line .

"incompatible types : java.util.date cannot be converted to java.sql.Date "

    String s = "2011-07-08";
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse(s);

i have to import the java.util.Date , But i have another error in the same line

unreported exception ParseException ; must be caught or declared to be thrown

2
  • i have to import the java.util.Date , But i have another error in the same line > unreported exception ParseException ; must be caught or declared to be thrown Commented Jan 26, 2014 at 3:42
  • The ParseException is a checked exception, so you are required to add a Try/Catch exception handler. If you are unaware of this, then you need some study on the basics of Java. Perhaps the Oracle Tutorial web site or Head First Java book from O’Reilly. Commented Jan 26, 2014 at 21:38

2 Answers 2

3

You've imported

java.sql.Date

instead of

java.util.Date

Change the import statement to the appropriate type, ie. java.util.Date.

Sign up to request clarification or add additional context in comments.

Comments

1

try

String s = "2011-07-08";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date date = sdf.parse(s);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.