Here you can find the source of dateToStr(Date date, int type)
public static String dateToStr(Date date, int type)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String dateToStr(Date date, int type) { switch (type) { case 0:/*from ww w . ja v a2 s. c o m*/ return dateToStr(date); case 1: return dateToStr(date, "yyyy/MM"); case 2: return dateToStr(date, "yyyyMMdd"); case 11: return dateToStr(date, "yyyy-MM-dd"); case 3: return dateToStr(date, "yyyyMM"); case 4: return dateToStr(date, "yyyy/MM/dd HH:mm:ss"); case 5: return dateToStr(date, "yyyyMMddHHmmss"); case 6: return dateToStr(date, "yyyy/MM/dd HH:mm"); case 7: return dateToStr(date, "HH:mm:ss"); case 8: return dateToStr(date, "HH:mm"); case 9: return dateToStr(date, "HHmmss"); case 10: return dateToStr(date, "HHmm"); case 12: return dateToStr(date, "yyyy-MM-dd HH:mm:ss"); } throw new IllegalArgumentException("Type undefined : " + type); } public static String dateToStr(Date date, String pattern) { if ((date == null) || (date.equals(""))) return null; SimpleDateFormat formatter = new SimpleDateFormat(pattern); return formatter.format(date); } public static String dateToStr(Date date) { return dateToStr(date, "yyyy/MM/dd"); } }