public static int[] parseTime(String s) {
if (s == null) {
throw new IllegalArgumentException();
}
Pattern pattern = Pattern.compile("([0-1]\\d|2[0-3]):([0-5]\\d):([0-5]\\d)");
Matcher matcher = pattern.matcher(s);
if (matcher.matches()) {
int hour = Integer.parseInt(matcher.group(1));
int minute = Integer.parseInt(matcher.group(2));
int second = Integer.parseInt(matcher.group(3));
return new int[] {hour, minute, second};
} else {
Sign in to make a reply
失眠是因为闲
public static int[] parseTime(String s) {
if (s == null) {
throw new IllegalArgumentException();
}
Pattern pattern = Pattern.compile("([0-1]\\d|2[0-3]):([0-5]\\d):([0-5]\\d)");
Matcher matcher = pattern.matcher(s);
if (matcher.matches()) {
int hour = Integer.parseInt(matcher.group(1));
int minute = Integer.parseInt(matcher.group(2));
int second = Integer.parseInt(matcher.group(3));
return new int[] {hour, minute, second};
} else {
throw new IllegalArgumentException();
}
}