Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
maheshqtech
Posts: 43
Registered: ‎11-24-2011
My Device: Perl
My Carrier: BB

change the date on clicking previous and next button

Hi,

In my application there are two buttons previous and next I want to make a code on the clicking on previous button which show the yesterday's date means current date-1 and on clicking on the next button show the tommrow date means current date+1 date

 

Can any one provide some sample code for this

 

Thanks in Advance

 

Please use plain text.
Super Contributor
pp
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: change the date on clicking previous and next button

Hi,

 

do something like this...

 

int MILLIS_IN_DAY = 1000 * 60 * 60 * 24;
  Date date = new Date();
  SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
  String prevDate = dateFormat.format(date.getTime() - MILLIS_IN_DAY);
  String currDate = dateFormat.format(date.getTime());
  String nextDate = dateFormat.format(date.getTime() + MILLIS_IN_DAY);
  System.out.println("Previous date: " + prevDate);
  System.out.println("Currnent date: " + currDate);
  System.out.println("Next date: " + nextDate);

 Regards,

pp

Please use plain text.