- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to list Short Month Names
To list short months, use the getShortMonths() from the DateFormatSymbols class in Java.
DateFormatSymbols is a class for encapsulating localizable date-time formatting data.
Get short month names in an array
String[] months = new DateFormatSymbols().getShortMonths();
Display the months
for (int i = 0; i < months.length - 1; i++) { String month = months[i]; System.out.println("Month ["+i+"] = " + month); }
The following is an example −
Example
import java.text.DateFormatSymbols; public class Demo { public static void main(String[] args) { // short months String[] months = new DateFormatSymbols().getShortMonths(); for (int i = 0; i < months.length - 1; i++) { String month = months[i]; System.out.println("Month ["+i+"] = " + month); } } }
Output
Month [0] = Jan Month [1] = Feb Month [2] = Mar Month [3] = Apr Month [4] = May Month [5] = Jun Month [6] = Jul Month [7] = Aug Month [8] = Sep Month [9] = Oct Month [10] = Nov Month [11] = Dec
Advertisements