Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private final static String YYYY_MM_dd = "yyyy-MM-dd"; public static String dateFormat(Date date, String format) { if (format == null || "".equals(format)) format = YYYY_MM_dd; SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(date); } }