Here you can find the source of toDate(int flag, Date... date)
public static String toDate(int flag, Date... date)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final String FORMAT_0 = "yyyy-MM-dd HH:mm:ss"; private static final String FORMAT_1 = "yyyy-MM-dd"; private static final String FORMAT_2 = "HH:mm:ss"; public static String toDate(int flag, Date... date) { SimpleDateFormat simple = null; if (flag == 0) simple = new SimpleDateFormat(FORMAT_0); else if (flag == 1) simple = new SimpleDateFormat(FORMAT_1); else/*from w w w.j a v a 2 s . c o m*/ simple = new SimpleDateFormat(FORMAT_2); if (date.length > 0) { return simple.format(date[0]); } return simple.format(new Date()); } }