Here you can find the source of calendarToString(Calendar calendar, String template)
public static String calendarToString(Calendar calendar, String template)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; public class Main { public static final String DATE = "yyyy-MM-dd"; public static String calendarToString(Calendar calendar, String template) { String stringCalendar = template; stringCalendar = stringCalendar.replace("{year}", String.valueOf(calendar.get(Calendar.YEAR))); stringCalendar = stringCalendar.replace("{month}", String.valueOf(calendar.get(Calendar.MONTH))); stringCalendar = stringCalendar.replace("{date}", String.valueOf(calendar.get(Calendar.DATE))); stringCalendar = stringCalendar.replace("{hour}", String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))); stringCalendar = stringCalendar.replace("{minute}", String.valueOf(calendar.get(Calendar.MINUTE))); stringCalendar = stringCalendar.replace("{second}", String.valueOf(calendar.get(Calendar.SECOND))); stringCalendar = stringCalendar.replace("{millisecond}", String.valueOf(calendar.get(Calendar.MILLISECOND))); return stringCalendar; }// ww w. j a va 2s . co m }