str=str.substring(int startIndex);
截取掉str从首字母起长度为startIndex的字符串,将剩余字符串赋值给str;
str=str.substring(int startIndex,int endIndex);
截取str中从startIndex开始至endIndex结束时的字符串,并将其赋值给str;
startIndex :开始处的索引(包括)
endIndex : 结束处的索引(不包括)
抛出异常:IndexOutOfBoundsException
如果 startIndex 为负,或 endIndex 大于此 String 对象的长度,或 startIndex大于 endIndex
日期格式转换
public class Solution {
public String dateConversion(String str) throws ParseException {
int year = Integer.parseInt(str.substring(0, 4));
int month = Integer.parseInt(str.substring(5, 7));
int day = Integer.parseInt(str.substring(8, 10));
return year+"年"+month+"月"+day+"日";
}
}