I'm trying to get the date from DateChooserCombo as follows
SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD");
String date = sdf.format(dateChooser.getDate());
But the method getDate() gives me error (illegal forward reference). I have also tried with getSelectedDate() but it's the same. What can I do?
Anyway I'm using Apache Netbeans 12.1 and the date picker should be this one: https://github.com/vadimig/jdatechooser
Thanks.
I downloaded the
JDateChoosercode from the link you provided in your question. There is nogetDate()method in classdatechooser.beans.DateChooserCombo. There is agetSelectedDate()method which returns an instance of class java.util.Calendar.Also, according to the documentation for class
java.text.SimpleDateFormat, the patternYYYY-MM-DDis a valid pattern but I don't think it's the pattern that you want.Dmeans day in year which means that 27th February is the 58th day of the year. You probably wantd. Similarly,YmeansWeek yearwhereas you probably wantedy.So, in order to get a string representation of the date that the user selected from the
DateChooserCombo, you probably want the following code.By the way, it appears that
JDateChooserdevelopment stopped seven years ago. Perhaps consider using JavaFX which has a DatePicker component which works with Java's date-time API.