- Trending Categories
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 by name and number in Java
Use the ‘b’ conversion character for month name in Java.
Use the ‘m’ conversion character for month number in Java.
Here, we are using Formatter and Calendar class, therefore import the following packages.
import java.util.Calendar; import java.util.Formatter;
The following is an example to display month name and number −
Example
import java.util.Calendar; import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); Calendar cal = Calendar.getInstance(); System.out.println("Current date and time: "+cal.getTime()); f = new Formatter(); System.out.println(f.format("Month = %tb
Month Number = %tm", cal, cal)); } }
Output
Current date and time: Mon Nov 26 07:07:31 UTC 2018 Month = Nov Month Number = 11
- Related Articles
- Display localized month name with printf method in Java
- Display the month number with SimpleDateFormat(“M”) in Java
- Get Month Name from Month number in MySQL?
- Display two-digit month in Java
- Display Month in MMM format in Java
- Display Month in MMMM format in Java
- Getting month name instead of numeric month number in report in SAP
- Display Month of Year using Java Calendar
- Display two-digit day of the month in Java
- Java Program to display previous month from GregorianCalendar
- How to convert number to month name in PHP?
- How to Convert Month Name to Number in Excel?
- Output only the name of the month instead of the month number in MySQL
- C# Program to display the number of days in a month
- Display the current method name in Java

Advertisements