Here you can find the source of toDateString(java.util.Date date, String spe)
public static String toDateString(java.util.Date date, String spe)
//package com.java2s; import java.util.Calendar; import java.text.SimpleDateFormat; public class Main { public static String toDateString(java.util.Date date, String spe) { if (date == null) return ""; Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w w w . ja v a 2 s. c o m*/ int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); int year = calendar.get(Calendar.YEAR); String monthStr = "" + month; String dayStr = "" + day; String yearStr = "" + year; if (month < 10) monthStr = "0" + month; if (day < 10) dayStr = "0" + day; return yearStr + spe + monthStr + spe + dayStr; } public static String toDateString(java.util.Date date) { return toDateString(date, "-"); } public static String toDateString(Calendar calendar) { return new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime()); } }