How do I Get a List of Month Names?
Category: java.text, viewed: 1320 time(s).
The example code below helps you to get all month names as an array of String. The first method, getMonths() return the full name string while the second method getShortMonths() return the short name of the month.
import java.text.DateFormatSymbols; public class MonthNames { public static void main(String[] args) { String[] months = new DateFormatSymbols().getMonths(); for (int i = 0; i < months.length; i++) { String month = months[i]; System.out.println("month = " + month); } String[] shortMonths = new DateFormatSymbols().getShortMonths(); for (int i = 0; i < shortMonths.length; i++) { String shortMonth = shortMonths[i]; System.out.println("shortMonth = " + shortMonth); } } } |
The result of the code above are:
month = January month = February month = March month = April month = May month = June month = July month = August month = September month = October month = November month = December shortMonth = Jan shortMonth = Feb shortMonth = Mar shortMonth = Apr shortMonth = May shortMonth = Jun shortMonth = Jul shortMonth = Aug shortMonth = Sep shortMonth = Oct shortMonth = Nov shortMonth = Dec
Can't find what you are looking for? Join our FORUMS and ask some questions!
Related Examples
- How do I format a number with leading zeros?
- How do I parse a number for a locale?
- How do I format a number for a locale?
- How do I iterate a subset of a string?
- How do I reverse a string using CharacterIterator?
- How do I iterate each characters of a string?
- How do I format a date-time value?
- How do I format a date into dd/mm/yyyy?
- How do I format a number?
- How do I convert Date to String?