- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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