I downloaded the JDateChooser
code from the link you provided in your question. There is no getDate()
method in class datechooser.beans.DateChooserCombo
. There is a getSelectedDate()
method which returns an instance of class java.util.Calendar.
Also, according to the documentation for class java.text.SimpleDateFormat
, the pattern YYYY-MM-DD
is a valid pattern but I don't think it's the pattern that you want. D
means day in year which means that 27th February is the 58th day of the year. You probably want d
. Similarly, Y
means Week year
whereas you probably wanted y
.
So, in order to get a string representation of the date that the user selected from the DateChooserCombo
, you probably want the following code.
DateChooserCombo dcc = new DateChooserCombo(); // or however you create and configure it
Calendar cal = dcc.getSelectedDate();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date = sdf.format(cal.getTime());
By the way, it appears that JDateChooser
development stopped seven years ago. Perhaps consider using JavaFX which has a DatePicker component which works with Java's date-time API.