Here you can find the source of FormatDate(Date date, String sf)
public static String FormatDate(Date date, String sf)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; public class Main { public static String FormatDate(Date date, String sf) { if (date == null) return ""; SimpleDateFormat dateformat = new SimpleDateFormat(sf); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); if (date.getHours() == 0) return sdf.format(date); else//w ww. j a va2 s. c om return dateformat.format(date); } }