Java Program get Month in short format


This Java example will show you how to get month name in short format, to display month name in short we will use DateFormatSymbols().getShortMonths() method

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("short Month = " + shortMonth);
      }
   }
}

 

Output:

short Month = Jun
short Month = Jul
short Month = Aug
short Month = Sep
short Month = Oct
short Month = Nov
short Month = Dec

 

 

 

We can also get month name in short by SimpleDateFormat class with format() method

 

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Calendar;

public class Main {
   public static void main(String[] args) {
      String str1 = "MMM";
      Date d = Calendar.getInstance().getTime();
      SimpleDateFormat sdf = new SimpleDateFormat(str1, Locale.FRENCH);
      System.out.println(sdf.format(d));
      sdf = new SimpleDateFormat(str1, Locale.ENGLISH);
      System.out.println(sdf.format(d));
   }
}

 

Output:

mai
May

 


Subscribe For Daily Updates

JAVA File IO examples

JAVA Date & Time Progamming Examples

JAVA Collections

Flutter Questions
Android Questions