Java examples for Date Time:SimpleDateFormat
Formatting Minutes using SimpleDateFormat
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)); } }