Display Month of Year using Java Calendar

Java 8Object Oriented ProgrammingProgramming

For using Calendar class, import the following package.

import java.util.Calendar;

Using the Calendar class, create an object.

Calendar calendar = Calendar.getInstance();

Now, create a string array of the month names.

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

Display the month name.

month[calendar.get(Calendar.MONTH)]

The following is an example.

Example

 Live Demo

import java.util.Calendar;
public class Demo {
   public static void main(String[] args) {
      Calendar calendar = Calendar.getInstance();
      String[] month = new String[] {"January", "February", "March", "April", "May", "June", "July", "August","September", "October", "November", "December" };
      System.out.println("Current Month = " + month[calendar.get(Calendar.MONTH)]);
   }
}

Output

The following is the output −

Current Month = Dec
raja
Published on 17-Dec-2018 10:11:13
Advertisements