Here you can find the source of getHour(String time)
public static String getHour(String time)
//package com.java2s; import java.text.*; public class Main { public static SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); public static String getHour(java.sql.Date date) { return timeFormat.format(date).substring(0, 2); }/*from ww w . ja va2 s.co m*/ public static String getHour(String time) { int hour = Integer.parseInt(time.substring(0, 2)); String ret_hour = null; if (hour > 12) { if (hour < 10) ret_hour = "0" + Integer.toString(hour - 12); else ret_hour = Integer.toString(hour - 12); } else { if (hour < 10) ret_hour = "0" + Integer.toString(hour); else ret_hour = time.substring(0, 2); } return ret_hour; } }