更新时间:2023-02-03 08:29:01
上面的例子,你可以尝试这样:
Given the example above, you could try something like this:
final int value = Integer.parseInt(input.substring(0, input.indexOf(':'))); //value = 12
其中 input = 12:15 pm
一般来说,只需使用 String#indexOf(String)
String#substring(int,int)
和 Integer.parseInt(String)
。
Generally speaking, just use a combination of String#indexOf(String)
, String#substring(int, int)
and Integer.parseInt(String)
.