Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String FORMAT_SHORT = "yyyy-MM-dd"; /** * templete: Date -> "yyyy-MM-dd" * * @param date * @return */ public static String date2short(Date date) { return date2str(date, FORMAT_SHORT); } /** * templete: Date -> FORMAT_STR * * @param date * @param format * @return */ public static String date2str(Date date, String format) { if (date == null) { return null; } SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern(format); return sdf.format(date); } }