adsense


Sunday, 25 October 2015

JAVA EXAMPLES DISPLAYING MONTHS IN SHORT FORMAT PAGE 65

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES DISPLAYING MONTHS IN SHORT FORMAT



Java Examples - Displaying months in short format



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


No comments: