private static String datePattern = "'.'YYYY-MM-dd";
public static void main(String[] args) {
System.out.println("---");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern);
String format = simpleDateFormat.format(new Date());
System.out.println(format);
System.out.println(simpleDateFormat);
}
Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'Y'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:768)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:575)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:500)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:475)
at Test.main(Test.java:14)
模板
正确 yyyy-MM-dd 错误 YYYY-MM-dd 在jdk 1.6 里面报错,1.8里面解析正常
jdk1.6
jdk1.8