Here you can find the source of setTime(Calendar cal, String time)
public static void setTime(Calendar cal, String time)
//package com.java2s; import java.util.Calendar; public class Main { public static void setTime(Calendar cal, String time) { int hour = 0; int minute = 0; int idx = time.indexOf(':'); if (idx < 0) { hour = Integer.parseInt(time); } else {//ww w . ja v a 2 s . c om hour = Integer.parseInt(time.substring(0, idx)); time = time.substring(idx + 1); idx = time.indexOf(':'); if (idx < 0) { minute = Integer.parseInt(time); idx = 1; } else { minute = Integer.parseInt(time.substring(0, idx)); idx = Integer.parseInt(time.substring(idx + 1)); } } cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, idx); } }