简体   繁体   中英

How to set current date to jDateChooser from pc?

I have a situation that I need to fill the jDateChooser box by the current date automatically (without clicking the pop up calender).

How can I do that?

Thanks in advance.

Date date = new Date();
dateChooser.setDate(date);

Here, the Date class belongs to the java.util package. So, either import java.util.Date or use:

java.util.Date date = new java.util.Date();
dateChooser.setDate(date);

To pick up the current date with desired format (format is necessary when you work with database) -

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
Date date = new Date(); 

Then just set it to the jdatechooser field

jDateChooser.setDate(date);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM