Here you can find the source of getTimeString(Calendar cal)
public static String getTimeString(Calendar cal)
//package com.java2s; import java.util.*; public class Main { public static String getTimeString(Calendar cal) { int hour = cal.get(Calendar.HOUR); int minute = cal.get(Calendar.MINUTE); boolean isAm = (cal.get(Calendar.AM_PM) == Calendar.AM); String hourStr;//from w w w .j a v a 2s .co m String minuteStr; if (!isAm) { hour += 12; } if (hour < 10) { hourStr = "0" + Integer.toString(hour); } else { hourStr = Integer.toString(hour); } if (minute < 10) { minuteStr = "0" + Integer.toString(minute); } else { minuteStr = Integer.toString(minute); } String timeStr = hourStr + ":" + minuteStr; return timeStr; } }