I am trying to make a getter for a JTextfield, the code looks like this
public Date getStartDate() {
return textFieldStartDate.getText();
}
I get the error
Type mismatch: cannot convert from String to Date
The problem is obvious, however i dont know how to solve it. I have been searching alot, but couldnt find a simple answer.
Try this:
public Date getStartDate() {
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
Date date = formatter.parse(textFieldStartDate.getText());
return date;
}