一个关于时间格式的奇怪问题,希望各位指点!
我这里有一段这样的代码:String formatter1 = "YYYYMMDDHH24MISS";
SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMDDHH24MISS");
String ti = "19840404121212";
Date date = sdf.parse(ti);
System.out.println(date);
System.out.println(ti);
不知道哪里出了错误,执行这段代码会抛出这样的异常:
java.lang.IllegalArgumentException: Illegal pattern character 'Y'
at java.text.SimpleDateFormat.compile(Unknown Source)
at java.text.SimpleDateFormat.initialize(Unknown Source)
at java.text.SimpleDateFormat.<init>(Unknown Source)
at java.text.SimpleDateFormat.<init>(Unknown Source)
at lineNo.main(lineNo.java:80)
如果把YYYYMMDDHH24MISS改成:yyyyMMDDHH24MISS则会抛出这样的异常:
java.lang.IllegalArgumentException: Illegal pattern character 'I'
at java.text.SimpleDateFormat.compile(Unknown Source)
at java.text.SimpleDateFormat.initialize(Unknown Source)
at java.text.SimpleDateFormat.<init>(Unknown Source)
at java.text.SimpleDateFormat.<init>(Unknown Source)
at lineNo.main(lineNo.java:80)
改成:yyyyMMDDHH24MiSS则是这样的异常:
java.lang.IllegalArgumentException: Illegal pattern character 'i'
at java.text.SimpleDateFormat.compile(Unknown Source)
at java.text.SimpleDateFormat.initialize(Unknown Source)
at java.text.SimpleDateFormat.<init>(Unknown Source)
at java.text.SimpleDateFormat.<init>(Unknown Source)
at lineNo.main(lineNo.java:80)
希望群的各位高手指点一下这是怎么回事啊,我得怎么改才能让他正常运行啊?