Here you can find the source of getDayStringByCalendar(Calendar calendar)
public static String getDayStringByCalendar(Calendar calendar)
//package com.java2s; //License from project: Apache License import java.util.Calendar; public class Main { public static String getDayStringByCalendar(Calendar calendar) { int m = calendar.get(Calendar.MONTH) + 1; String month = ""; if (m >= 10) month = "" + m; else//from w ww.j a v a 2 s .co m month = "0" + m; int d = calendar.get(Calendar.DAY_OF_MONTH); String day = ""; if (d >= 10) day += d; else day = "0" + d; String s = calendar.get(Calendar.YEAR) + month + day; return s; } public static String getDayStringByCalendar(Long timeMillis) { if (timeMillis == 0) { return "19800000"; } Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timeMillis); int m = calendar.get(Calendar.MONTH) + 1; String month = ""; if (m >= 10) month = "" + m; else month = "0" + m; int d = calendar.get(Calendar.DAY_OF_MONTH); String day = ""; if (d >= 10) day += d; else day = "0" + d; String s = calendar.get(Calendar.YEAR) + month + day; return s; } }