Here you can find the source of appendDate(StringBuffer sb, Calendar cal)
private static void appendDate(StringBuffer sb, Calendar cal)
//package com.java2s; import java.util.Calendar; public class Main { private static void appendDate(StringBuffer sb, Calendar cal) { int l_year = cal.get(Calendar.YEAR); // always use at least four digits for the year so very // early years, like 2, don't get misinterpreted ///*from w w w . j a v a 2 s . co m*/ int l_yearlen = String.valueOf(l_year).length(); for (int i = 4; i > l_yearlen; i--) { sb.append("0"); } sb.append(l_year); sb.append('-'); int l_month = cal.get(Calendar.MONTH) + 1; if (l_month < 10) sb.append('0'); sb.append(l_month); sb.append('-'); int l_day = cal.get(Calendar.DAY_OF_MONTH); if (l_day < 10) sb.append('0'); sb.append(l_day); } }