Here you can find the source of getCalendarDate(Calendar calendar)
public static final String getCalendarDate(Calendar calendar)
//package com.java2s; import java.util.Calendar; public class Main { public static final String getCalendarDate(Calendar calendar) { String year = String.valueOf(calendar.get(Calendar.YEAR)); String month = String.valueOf(calendar.get(Calendar.MONTH) + 1); if (month.length() < 2) month = "0" + month; String date = String.valueOf(calendar.get(Calendar.DATE)); if (date.length() < 2) date = "0" + date; String hours = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)); if (hours.length() < 2) hours = "0" + hours; /*String hours = String.valueOf(calendar.get(Calendar.HOUR)); if (calendar.get(Calendar.AM_PM ) == 1) hours = String.valueOf(Integer.parseInt(hours) + 12); if (hours.length() < 2)// w ww .j a v a 2 s . com hours = "0" + hours;*/ String minutes = String.valueOf(calendar.get(Calendar.MINUTE)); if (minutes.length() < 2) minutes = "0" + minutes; /*String second = String.valueOf(calendar.get(Calendar.SECOND)); if (second.length() < 2) second = "0" + second;*/ return year + "/" + month + "/" + date + " " + hours + ":" + minutes; } }