Java SimpleDateFormat format minute as "1", "01"

Description

Java SimpleDateFormat format minute as "1", "01"

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



PreviousNext

Related