- 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 two-digit month in Java
Use the ‘m’ date conversion character to display two-digit month.
System.out.printf("Two-digit month: %tm
",d);
Above, d is a date object −
Date d = new Date();
The following is an example −
Example
import java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; public class Demo { public static void main(String[] args) throws Exception { Date d = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a"); String format = dateFormat.format(d); System.out.println("Current date and time = " + format); System.out.printf("Four-digit Year = %TY
",d); System.out.printf("Two-digit Year = %ty
",d); System.out.printf("Three-digit Day of the Year: %tj/%Tj
", d, d); System.out.printf("Two-digit month: %tm
",d); } }
Output
Current date and time = 26/11/2018 12:18:51 PM Four-digit Year = 2018 Two-digit Year = 18 Three-digit Day of the Year: 330/330 Two-digit month: 11
- Related Articles
- Display two-digit day of the month in Java
- Display two-digit year in Java
- Display first two digits of year in Java (two-digit century)
- Display Month in MMM format in Java
- Display Month in MMMM format in Java
- Display four-digit year in Java
- Display month by name and number in Java
- Display Month of Year using Java Calendar
- Display the month number with SimpleDateFormat(“M”) in Java
- Display localized month name with printf method in Java
- Java Program to display previous month from GregorianCalendar
- Display three-digit day of the year in Java
- Display three letter-month value with SimpleDateFormat('MMM') in Java
- Java Program to Enter a Number in Digit and Display in Words
- Display two digits day number in Java

Advertisements