Here you can find the source of DateToString(Date date)
public static String DateToString(Date date)
//package com.java2s; import java.sql.Date; import java.util.Calendar; public class Main { public static String DateToString(Date date, String separador) { if (date == null) { return null; }//from w w w . j a v a 2s . c o m Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int dia = calendar.get(Calendar.DAY_OF_MONTH); String stringDia = dia < 10 ? "0" + dia : String.valueOf(dia); int mes = calendar.get(Calendar.MONTH) + 1; String stringMes = mes < 10 ? "0" + mes : String.valueOf(mes); int ano = calendar.get(Calendar.YEAR); String dataEmString = stringDia + separador + stringMes + separador + ano; return dataEmString; } public static String DateToString(Date date) { return DateToString(date, "-"); } }