Get/Find All Months Using Java API

In this example we are showing How To Display all Months Using Java API
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data, such as the names of the months, the names of the days of the week, and the time zone data. DateFormat and SimpleDateFormat both use DateFormatSymbols to encapsulate this information.
Reference -> http://docs.oracle.com/javase/7/docs/api/java/text/DateFormatSymbols.html
Following are the important methods avaialbe on DateFormatSymbols class
Get/Find all Months Using Java API
package com.test;
import java.text.DateFormatSymbols;
import java.util.Arrays;
import java.util.Locale;
public class FindAllMonthsInJava {
/**
* Get All Months / Short Months / Locale Months In Java
*/
public static void main(String[] args) {
//Get List of Month Names
System.out.println("All Months: " + Arrays.toString(new DateFormatSymbols().getMonths()));
//Get List of Short Month Name
System.out.println("Short Months: " + Arrays.toString(new DateFormatSymbols().getShortMonths()));
//Get List of Month Names Using Locale
System.out.println("All Months In French: " + Arrays.toString(new DateFormatSymbols(Locale.FRENCH).getMonths()));
//Get List of Short Month Name Using Locale
System.out.println("Short Months In French: " + Arrays.toString(new DateFormatSymbols(Locale.FRENCH).getShortMonths()));
}
}
import java.text.DateFormatSymbols;
import java.util.Arrays;
import java.util.Locale;
public class FindAllMonthsInJava {
/**
* Get All Months / Short Months / Locale Months In Java
*/
public static void main(String[] args) {
//Get List of Month Names
System.out.println("All Months: " + Arrays.toString(new DateFormatSymbols().getMonths()));
//Get List of Short Month Name
System.out.println("Short Months: " + Arrays.toString(new DateFormatSymbols().getShortMonths()));
//Get List of Month Names Using Locale
System.out.println("All Months In French: " + Arrays.toString(new DateFormatSymbols(Locale.FRENCH).getMonths()));
//Get List of Short Month Name Using Locale
System.out.println("Short Months In French: " + Arrays.toString(new DateFormatSymbols(Locale.FRENCH).getShortMonths()));
}
}
Output
All Months: [January, February, March, April, May, June, July, August, September, October, November, December, ]Short Months: [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, ]
All Months In French: [janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre, ]
Short Months In French: [janv., févr., mars, avr., mai, juin, juil., août, sept., oct., nov., déc., ]
Get/Find Current Month Using Java
package com.test;
import java.text.SimpleDateFormat;
import java.util.Date;
public class GetCurrentMonthInJava {
/**
* Get / Find Current Month In Java
*/
public static void main(String[] args) {
SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM");
System.out.println("Current Month: "+ dateFormat.format(new Date()));
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
public class GetCurrentMonthInJava {
/**
* Get / Find Current Month In Java
*/
public static void main(String[] args) {
SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM");
System.out.println("Current Month: "+ dateFormat.format(new Date()));
}
}
Output
Current Month: May