Java tutorial
//package com.java2s; public class Main { /** * * @param HHmm * @return */ public static String to12Hours(String HHmm) { String[] t = HHmm.trim().split(":"); int start = Integer.parseInt(t[0]); String a = "am"; if (start > 12) { start -= 12; a = "pm"; } return String.valueOf(start) + ":" + t[1] + a; } }