Get Month Name Example

In this Example we want to describe you a code that help you in understanding a how to get a 'Get Month Name Example'.

Get Month Name Example

In this Example we want to describe you a code that help you in understanding a how to get a 'Get Month Name Example'.

Get Month Name Example

Get Month Name Example

     

In this Example we want to describe you a code that help you in understanding a how to get a 'Get Month Name Example'.For this we have a class name 'GetMonthNameExample'. Inside the main method we declared a String array name month name. This String array variable is initialized with month name values.

1)getInstance ( )  -  This method return you the calendar object with a specific time zone and locale.

2)get(Calendar.Month) - This get  method return you the current month

Finally the System.out.print print the Month name  from String variable month.

GetMonthNameExample.java

import java.util.*;

public class GetMonthNameExample {

  public static void main(String args[]) {

  String[] monthName = {"January""February",
  "March""April""May""June""July",
  "August""September""October""November",
  "December"
  };

  Calendar cal = Calendar.getInstance();
  String month = monthName[cal.get(Calendar.MONTH)];
  System.out.println("Month name: " + month);
  }
}

Output:

Month name: October


Download code