This program will get all months of current year .
Source Code:
import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.*;
public class test {
public static void main(String[] args){
ArrayList monthYearList = new ArrayList();
String[] months = new DateFormatSymbols().getMonths();
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
String yearInString = String.valueOf(year);
for (int i = 0; i < months.length; i++) {
String month = months[i];
if(month!=null&& !month.equals("")){
month = month.substring(0, 3).concat("-").concat(yearInString);
System.out.println("month are"+month);
monthYearList.add(month);
}
}
}
}
No comments:
Post a Comment