Web | This Site

Java Basics Examples
Java Tutorial
Java Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | Discussion Forums |  | About TP

# Java Examples - Displaying shorted months

## Problem Description:

How to display name of the months in short format?

## Solution:

This example displays the names of the months in short form with the help of DateFormatSymbols().getShortMonths() method of DateFormatSymbols class.

    import java.text.SimpleDateFormat;
    import java.text.DateFormatSymbols;

    public class Main {
       public static void main(String[] args) {
          String[] shortMonths = new DateFormatSymbols()
          .getShortMonths();
          for (int i = 0; i < (shortMonths.length-1); i++) {
             String shortMonth = shortMonths[i];
             System.out.println("shortMonth = " + shortMonth);
          }
       }
    }

## Result:

The above code sample will produce the following result.

    shortMonth = Jan
    shortMonth = Feb
    shortMonth = Mar
    shortMonth = Apr
    shortMonth = May
    shortMonth = Jun
    shortMonth = Jul
    shortMonth = Aug
    shortMonth = Sep
    shortMonth = Oct
    shortMonth = Nov
    shortMonth = Dec

Advertisement

Online Image Processing

Indian Baby Names