Here you can find the source of dateToString(Date date)
public static String dateToString(Date date)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static String dateToString(Date date) { int y, m, d; Calendar c = Calendar.getInstance(); String dateString = null; c.setTime(date);//from w ww . j ava 2 s . c o m y = c.get(Calendar.YEAR); m = c.get(Calendar.MONTH) + 1; d = c.get(Calendar.DATE); dateString = (y < 10 ? "0" : "") + y + "-" + (m < 10 ? "0" : "") + m + "-" + (d < 10 ? "0" : "") + d; c = null; return dateString; } }