on 05-13-2008 6:43 AM
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...
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.