import java.util.*;
import java.text.*;
public class DateConverter {
public static void main(String []args){
/*分割符a之间的字符串需是数字型的字符串。否则运行时java.lang.NumberFormatException*/
String s="2005a04a30";
StringTokenizer st=new StringTokenizer(s,"a");//建立一个在String s中以a为分割符的对象
int year=Integer.parseInt(st.nextToken());
int month=Integer.parseInt(st.nextToken());
int day=Integer.parseInt(st.nextToken());
System.out.println("year: "+year);
System.out.println("month: "+month);
System.out.println("day: "+day);
String s1="20050430";
// int all=Integer.parseInt(s); //运行时java.lang.NumberFormatException
int all=Integer.parseInt(s1);
System.out.println("all: "+all);
}
}
output:
year: 2005
month: 4
day: 30
all: 20050403