cancel
Showing results for 
Search instead for 
Did you mean: 

How to Get Next Month?

Former Member
0 Kudos

I am using the following code to get current month in "MMM" format.

String month1 = (new SimpleDateFormat("MMM").format(new Date()));

How can i get the subsequent months?

for example:

if current month1 = "May". then month2 should be "Jun" and month3 should be "July" and so on...

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Abdulla,

Try following code:

	Calendar cal = Calendar.getInstance();
	String [] months = new String[12];
	for(int i=0;i<months.length;i++){
		cal.set(Calendar.MONTH,cal.get(Calendar.MONTH) + 1);
		months<i> = new SimpleDateFormat("MMM").format(cal.getTime());
	}

Regards,

Gopal

Answers (2)

Answers (2)

nikhil_bose
Active Contributor
0 Kudos

easy way to work around Date is Calendar Class.

as gopal mentioned,

Calendar cal = Calendar.getInstance();

you can change month by

cal.set( Calendar.MONTH, cal.get( Calendar.MONTH) + 1);

// this will move to next months as incrementing by 1

String month1 = new SimpleDateFormat("MMM").format(cal.getTime());

nikhiL

Former Member
0 Kudos

Hi Abdullah,

U can use the following code,though using some deprecated methods,this solves the purpose.

Displays all month names from May to Dec

java.util.Date dt= new Date();

for(int i=dt.getMonth()1;i<=12;i+)

{

* *

* String month1 = (new SimpleDateFormat("MMM").format(dt));*

* wdComponentAPI.getMessageManager().reportSuccess("Mon "i"=="+month1);*

* *

* Calendar calendar=new GregorianCalendar(dt.getYear(),dt.getMonth()+1,1);*

* java.util.Date nextDate = calendar.getTime(); *

* dt=nextDate;*

* *

}

Hope it helps

Rgds,

Santhosh