Set current date to jDateChooser

I'm working on a project in netbeans and MySQL Workbech.
I have a Signup form and I want the user to pick a date. If they don't pick a date I want to use today's date as default.

I'm using jcalendar 1.4. How can I set today's date as a default?

I've already used

jDateChooser1.setDateFormatString("yyyy-mm-dd "); 

so that my date would be compatible with MySQL DATE format.

Upvotes: 0

Views: 2057

Answers (1)

Mohammad
Mohammad

Reputation: 1577

To set today's date with format :

 DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
 LocalDateTime now = LocalDateTime.now();  
 String currDateString = dateFormat.format(now);
 JdateChooser.setDate(now);

you can also do this :

   java.util.Date date2 = new SimpleDateFormat("yyyy-MM-dd").parse(currDateString );

update: based your comment it will work :

jDateChooser1.setDate(java.sql.Date.valueOf(java.time.LocalDate.now())); 
pst.setString(5,((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText()); 

Upvotes: 1

Related Questions