Erfan Ahmed
Erfan Ahmed

Reputation: 1613

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.

Upvotes: 3

Views: 16994

Answers (3)

Erfan Ahmed
Erfan Ahmed

Reputation: 1613

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);

Upvotes: 0

Abdul Waquar
Abdul Waquar

Reputation: 31

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);

Upvotes: 0

hakim el massari
hakim el massari

Reputation: 79

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

Upvotes: 4

Related Questions