Search code examples
javanetbeansjdatechooser

JDateChooser setDateFormat while input into database


ps.setString(26, ((JTextField) Birthday.getDateEditor().getUiComponent()).getText());

That is my code how can i Convert the date format into MMM d, yyyy because the default format of my JDateChooser is yyyy-MM-dd.


Solution

  • Try this:

    DateFormat f = new SimpleDateFormat("MMM d, yyyy");
    ps.setString(26, f.format(((JTextField) Birthday.getDateEditor().getUiComponent()).getText()));
    

    CORRECTION

    DateFormat f = new SimpleDateFormat("MMM d, yyyy");
    ps.setString(26, f.format(Birthday.getDate()));