Formatting Minutes using SimpleDateFormat - Java Date Time

Java examples for Date Time:SimpleDateFormat

Description

Formatting Minutes using SimpleDateFormat

Demo Code

 
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class Main {
 
  public static void main(String[] args) {
     Date date = new Date();
   //from  www .  ja  v a  2 s.  c  o  m
     //formatting minute in m format like 1,2 etc.
     String strDateFormat = "m";
     SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
     
     System.out.println("minutes in m format : " + sdf.format(date));
     
     //formatting minutes in mm format like 01, 02 etc.
     strDateFormat = "mm";
     sdf = new SimpleDateFormat(strDateFormat);
     System.out.println("minutes in mm format : " + sdf.format(date));
  }
}
 

Result


Related Tutorials