我知道Java Date Time不是一个好的前进方式,但我只是好奇发生了什么:
为什么下面这行代码不会产生任何错误:
为什么下面这行代码不会产生任何错误:
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy", Locale.US)
而下面这两行却会产生错误:
DateFormat df = new SimpleDateFormat("DD-MMM-YYYY", Locale.US)
DateFormat df = new SimpleDateFormat("dd-mm-YYYY", Locale.US)
会抛出以下异常:Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'Y'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:769)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:576)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:501)
at testing.MySchedule.main(MySchedule.java:18)
我的意思是,我只是改变了大小写,但DateFormat难道真的那么愚蠢吗?还是我做错了什么?或者这与我使用的区域设置有关?
谢谢!