Link to home
Start Free TrialLog in
Avatar of WennySY
WennySY

asked on

Display current date,month,and year to JTextField

I have two JTextField :
1. BorrowDate
2. ReturnDate
In the Borrow Date I want to display current date month and year .
In the Return Date I want to display 7 days after the current date month and year .

what is the code for those?
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try like:

Date dToday = new Date();
SimpleDateFormat ft1 = new SimpleDateFormat("dd/MM/yyyy");
String dBorrowDate = ft1.format(dToday);

Date d7Days = new Date(dToday.getTime() + (7 * 1000 * 60 * 60 * 24));
String dReturnDate = ft1.format(d7Days);

BorrowDate.setText(dBorrowDate);
ReturnDate.setText(dReturnDate);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial