日期:2014-05-20 浏览次数:20723 次
public class Test { public static void main(String[] args) { String time = "2359"; System.out.println(getMinutes(time)); } public static int getMinutes(String time) { if (time.length() != 4) { return -1; } int hour = Integer.parseInt(time.substring(0, 2)); int minute = Integer.parseInt(time.substring(2)); if (hour < 0 || hour > 23 || minute < 0 || minute > 59) { return -1; } return hour * 60 + minute; } }