Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Display Month of Year using Java Calendar
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
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
Advertisements
