![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 day of the month in Java
Use the ‘d’ date conversion character to display two-digit day of the month, for example, 27, 28, 20, etc.
System.out.printf("Two-digit day of the month: %td
",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
", d); System.out.printf("Two-digit month: %tm
",d); System.out.printf("Two-digit day of the month: %td
",d); } }
Output
Current date and time = 26/11/2018 12:20:33 PM Four-digit Year = 2018 Two-digit Year = 18 Three-digit Day of the Year: 330 Two-digit month: 11 Two-digit day of the month: 26
Advertisements