Java tutorial
//package com.java2s; import android.util.Log; import java.util.Calendar; public class Main { private static String findNext(Calendar cal, String[] arr) { for (String s : arr) { if (isBefore(cal, s)) { return s; } } Log.i("utils.java findNext", "no next bus found for date:" + cal.toString()); return null; } private static boolean isBefore(Calendar date, String time) { try { String[] arr = time.split(":"); int hours = Integer.parseInt(arr[0]); int mins = Integer.parseInt(arr[1]); return (date.get(Calendar.HOUR_OF_DAY) < hours) || (date.get(Calendar.HOUR_OF_DAY) == hours && date.get(Calendar.MINUTE) < mins); } catch (Exception e) { Log.e("Utils.java isBefore", "The supplied times are not properly formatted. Verify that your schedule times follow the hh:mm pattern"); return true; } } }