public static int[] parseTime(String s) {
// FIXME:
if(s==null) {
throw new IllegalArgumentException();
}
Pattern pattern=Pattern.compile("([0-1][0-9]||2[0-3]):([0-5][0-9]):([0-5][0-9])");
Matcher matcher=pattern.matcher(s);
int[] array=new int[3];
if(matcher.matches()) {
String hour=matcher.group(1);
String minute=matcher.group(2);
String second=matcher.group(3);
array[0]=Integer.valueOf(hour);
array[1]=Integer.valueOf(minute);
array[2]=Integer.valueOf(second);
// Integer hour=Integer.parseInt(matcher.group(1));//两种都可以
// Integer minute=Integer.parseInt(matcher.group(2));
// Integer second=Integer.parseInt(matcher.group(3));
// array[0]=hour;
// array[1]=minute;
// array[2]=second;
return array;
}else {
Sign in to make a reply
乞与追逐
public static int[] parseTime(String s) {
// FIXME:
if(s==null) {
throw new IllegalArgumentException();
}
Pattern pattern=Pattern.compile("([0-1][0-9]||2[0-3]):([0-5][0-9]):([0-5][0-9])");
Matcher matcher=pattern.matcher(s);
int[] array=new int[3];
if(matcher.matches()) {
String hour=matcher.group(1);
String minute=matcher.group(2);
String second=matcher.group(3);
array[0]=Integer.valueOf(hour);
array[1]=Integer.valueOf(minute);
array[2]=Integer.valueOf(second);
// Integer hour=Integer.parseInt(matcher.group(1));//两种都可以
// Integer minute=Integer.parseInt(matcher.group(2));
// Integer second=Integer.parseInt(matcher.group(3));
// array[0]=hour;
// array[1]=minute;
// array[2]=second;
return array;
}else {
throw new IllegalArgumentException();
}
}
}