Here you can find the source of createDateStr(Calendar calendar)
public static String createDateStr(Calendar calendar)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static final String DATE_DELIMITER = "-"; public static String createDateStr(Calendar calendar) { int monthInt = calendar.get(Calendar.MONTH) + 1; String monthStr = monthInt < 10 ? "0" + monthInt : "" + monthInt; int dayInt = calendar.get(Calendar.DAY_OF_MONTH); String dayStr = dayInt < 10 ? "0" + dayInt : "" + dayInt; String dateStr = calendar.get(Calendar.YEAR) + DATE_DELIMITER + monthStr + DATE_DELIMITER + dayStr; return dateStr; }/* w w w . ja v a2 s . c om*/ public static String createDateStr(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return createDateStr(calendar); } }