DateFormatSymbols getMonths() Method in Java with Examples
The getMonths() Method of DateFormatSymbols class in Java is used to get the name of the months of the calendar in a string format.
Syntax:
public String[] getMonths()
Parameters: The method does not take any parameters.
Return Values: The method returns the name of the months in a string format.
Below programs illustrate the use of getMonths() method.
Example 1:
// Java code to demonstrate getMonths() import java.text.DateFormatSymbols; public class DateFormat_Main { public static void main(String args[]) { int i; // Initializing DateFormatSymbols String months[] = new DateFormatSymbols().getMonths(); for (i = 0; i < months.length - 1; i++) { // Displaying the months System.out.println("Month = " + months[i]); } } } |
Month = January Month = February Month = March Month = April Month = May Month = June Month = July Month = August Month = September Month = October Month = November Month = December
Example 2:
// Java code to demonstrate getMonths() import java.text.DateFormatSymbols; public class DateFormat_Main { public static void main(String args[]) { int i; // Initializing DateFormatSymbols String months[] = new DateFormatSymbols().getMonths(); for (i = 0; i < months.length / 2; i++) { // Displaying the months System.out.println("Month " + i + " = " + months[i]); } } } |
Month 0 = January Month 1 = February Month 2 = March Month 3 = April Month 4 = May Month 5 = June
Reference: https://docs.oracle.com/javase/8/docs/api/java/text/DateFormatSymbols.html#getMonths–
Recommended Posts:
- Period getMonths() method in Java with Examples
- DateFormatSymbols getShortWeekdays() Method in Java with Examples
- DateFormatSymbols getWeekdays() Method in Java with Examples
- DateFormatSymbols getEras() Method in Java with Examples
- DateFormatSymbols setShortMonths() Method in Java with Examples
- DateFormatSymbols getAvailableLocales() Method in Java with Examples
- DateFormatSymbols setShortWeekdays() Method in Java with Examples
- DateFormatSymbols setMonths() Method in Java with Examples
- DateFormatSymbols setWeekdays() Method in Java with Examples
- DateFormatSymbols getAmPmStrings() Method in Java with Examples
- DateFormatSymbols getShortMonths() Method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


