Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static int[] parseTime(String timeString) { String[] splitTimeString = timeString.split(":"); int hour = Integer.parseInt(splitTimeString[0]); int minute = Integer.parseInt(splitTimeString[1]); if (hour < 0 || hour > 23) { throw new RuntimeException("Failed to parse time: Hours was '" + hour + "' and must be between 00 and 23. Time format is HH-mm (ex: '23:49')"); } else if (minute < 0 || minute > 59) { throw new RuntimeException("Failed to parse time: Minutes was '" + minute + "' and must be between 00 and 59. Time format is HH-mm (ex: '23:49')"); } else { int[] time = { hour, minute }; return time; } } }