Java Program to Display Name of a Month in (MMM) Format
Java is a most powerful programming language, by which we can do many things and Java is an industry preferable language. So it has a huge field of features. Here we discuss one of the best features of Java, that is how we can represent Month in a short form or MMM Format.
There are two ways to do this using some classes:
Method 1: Using SimpleDateFormat and Date class
- Here Date class provides the current date and time, and SimpleDateFormat class use to format the date in some format, here the month will be shown in MMM format.
- SimpleDateFormat class comes under Text package in Java and Date class comes under the util package in Java. Date constructor initializes the object with the current date and time.
- SimpleDateFormat is a class for formatting and parsing date.
Method 2: Using Formatter class
- We can use Formatter class to print the month in short form.
- Here we use this class with Date class. There is format specifier “%tb” is use to print short month.
- There are many format specifier for other works also. If we use “%tB”, then it will become full month. See below code,
Method 3: Use Formatter class with Calendar class
This class also returns the current date and time.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.