Calendar: adding a day time the button is clicked [Java] -


class calendarndlistener implements  actionlistener{     public void actionperformed(actionevent e){             calendar = new gregoriancalendar();             format = new simpledateformat("dd/mm");             date = new date();              calendar.settime(date);             calendar.add(calendar.date, 1);             date = calendar.gettime();              dag.settext(format.format(date));         } 

when click button has 'calendarndlistener' actionlistener it, adds 1 day 'dag' label. once. if want go day ahead, doesn't anything. want is, when click button, adds day label date. if click again, adds day previous date (the 1 has day added it). it's 2 days ahead of current day.

what want: today 28/03. when click button, goes 29/03. when click again, goes 30/03 , on.

what now: today 28/03. when click button, goes 29/03. when click again, stays @ 29/03.

i hope clear enough, might sound confusing. bear in mind i'm still beginner in java programming.

the question asked before! research instead of posting question! answer:

public class dateutil {     public static date adddays(date date, int days)     {         calendar cal = calendar.getinstance();         cal.settime(date);         cal.add(calendar.date, days); //minus number decrement days         return cal.gettime();     } } 

to add 1 day, per click, call this:

string sourcedate = "2012-02-29"; simpledateformat format = new simpledateformat("yyyy-mm-dd"); date mydate = format.parse(sourcedate); mydate = dateutil.adddays(mydate, 1); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -