- 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 minutes with SimpleDateFormat('mm') in Java
To work with SimpleDateFormat class in Java, import the following package.
import java.text.SimpleDateFormat;
Now, set the format with SimpleDateFormat(“mm”) to display minutes in two-digits.
Format f = new SimpleDateFormat(‘”mm”);
Now, get the minutes in a string.
String strMinute = f.format(new Date());
The following is an example −
Example
import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("dd/MMMM/yyyy hh:mm:s"); System.out.println("Today's date = "+simpleformat.format(cal.getTime())); // displaying hour Format f = new SimpleDateFormat("H"); String strHour = f.format(new Date()); System.out.println("Current Hour = "+strHour); // displaying minutes in two-digits f = new SimpleDateFormat("mm"); String strMinute = f.format(new Date()); System.out.println("Current Minutes = "+strMinute); } }
Output
Today's date = 26/November/2018 08:03:40 Current Hour = 8 Current Minutes = 03
- Related Articles
- Display minutes with SimpleDateFormat(“m”) in Java
- Display hour with SimpleDateFormat(“H”) in Java
- Display today’s date in Java with SimpleDateFormat
- Display hour with SimpleDateFormat(“hh”) in Java
- Display seconds with SimpleDateFormat(“s”) in Java
- Display time zone with SimpleDateFormat(“z”) in Java
- Format date with SimpleDateFormat('MM/dd/yy') in Java
- Display the month number with SimpleDateFormat(“M”) in Java
- Display seconds with SimpleDateFormat('ss') in Java
- Display year with SimpleDateFormat('yyyy') in Java
- Display AM/PM time marker with SimpleDateFormat(“a”) in Java
- Display day number with SimpleDateFormat('d') in Java
- Format Minutes in mm format in Java
- Display three letter-month value with SimpleDateFormat('MMM') in Java
- Set Date patterns with SimpleDateFormat in Java

Advertisements