date popultation

is there a way in java to populate a textfield with the current date in mm/dd/yyyyy format..also i have a button + and - next to it..when i hit +, it should have the textfield go to the next day and - to the previous day...thanks
trance12Asked:
Who is Participating?
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.

suprapto45Commented:
Hi,

You can do it like

Format formatter;
Date date = new Date();
formatter = new SimpleDateFormat("MM/dd/yyyy");
String s = formatter.format(date);

JTextField j = new JTextField();
j.setText(s);

Then for the button + or -,
please refer to this URL
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21467234.html

or

Format formatter;
Date date = new Date();
formatter = new SimpleDateFormat("MM/dd/yyyy");
long val = currentDate.getTime() + 1000*60*60*24;  // Add one day, to subtract one day, use currentDate.getTime() - 1000*60*60*24;
String s = formatter.format(new Date(val));

JTextField j = new JTextField();
j.setText(s);

I hope that helps.

Regards
Dave

suprapto45Commented:
Typo...

Format formatter;
Date date = new Date();
formatter = new SimpleDateFormat("MM/dd/yyyy");
long val = date.getTime() + 1000*60*60*24;  // Add one day, to subtract one day, use currentDate.getTime() - 1000*60*60*24;
String s = formatter.format(new Date(val));

Regards
Dave
Mayank SPrincipal TechnologistCommented:
http://www.javaalmanac.com/egs/java.text/FormatDate.html

You can use Calendar.add ( Calendar.DAY, 1 ) ; for adding....
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

trance12Author Commented:
it doesnt work??


 Format formatter;
                    Date date = new Date();
                    formatter = new SimpleDateFormat("MM/DD/yyyy");
                    String s = formatter.format(date);
        dateTextField.setText(s)

gives me 07/192/2005 instead of 07/11/2005??
trance12Author Commented:
also for the + and - , it should'nt be the current date + 1 , rather i'd like it to be whatever is in the textfield +1..is that possible?
Mayank SPrincipal TechnologistCommented:
>> new SimpleDateFormat("MM/DD/yyyy");

Make it: new SimpleDateFormat("MM/dd/yyyy"); // the 'dd' is in small case
Mayank SPrincipal TechnologistCommented:
>> i'd like it to be whatever is in the textfield +1..is that possible?

Yeah.

Calendar cal = Calendar.getInstance () ;
formatter = new SimpleDateFormat ( "MM/dd/yyyy" ) ;
cal.setTime ( formatter.parse ( dateTextField.getText () ) ) ;
cal.add ( Calendar.DATE, 1 ) ;
dateTextField.setText ( formatter.format ( cal.getTime () ) ) ;

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
trance12Author Commented:
thanks..gives me this error though

cal.setTime( formatter.parse( lTextField.getText ())) ;

CalendarDate.java [44:1] cannot resolve symbol
symbol  : method parse (java.lang.String)
location: class java.text.Format
cal.setTime( formatter.parse( lTextField.getText ())) ;
                      ^
1 error
Errors compiling CRMCalendarDate.

Mayank SPrincipal TechnologistCommented:
SimpleDateFormat formatter = new SimpleDateFormat ( "MM/dd/yyyy" ) ;
trance12Author Commented:
thanks heaps..worked fine..i'll split the points between the two of you for the feedback..
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
Java

From novice to tech pro — start learning today.