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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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);


Open in new window

Not a good idea to roll your own date maths. Not only is it unnecessary but it's error prone in more than one way. Try

        Calendar cal = Calendar.getInstance();
        SimpleDateFormat ft1 = new SimpleDateFormat("dd/MM/yyyy");
        String sBorrowDate = ft1.format(cal.getTime());

        cal.add(Calendar.DATE, 7);
        String sReturnDate = ft1.format(cal.getTime());


Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.