Java tutorial
//package com.java2s; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Calendar; import java.util.Date; public class Main { private static final Calendar calendar = Calendar.getInstance(); private static final NumberFormat format = new DecimalFormat("00"); public static String buildShiftTimeRepresentation(Date shiftTime) { calendar.setTime(shiftTime); String s = ""; s = format.format(calendar.get(Calendar.HOUR) == 0 ? 12 : calendar.get(Calendar.HOUR)); s += ":" + format.format(calendar.get(Calendar.MINUTE)); s += calendar.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM"; return s; } }