I know Java Date Time is not a good way to go forward but I was just curious as to what's happening:
Why does the following line:
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy", Locale.US)
not produce any errors and the following lines do:
DateFormat df = new SimpleDateFormat("DD-MMM-YYYY", Locale.US)
DateFormat df = new SimpleDateFormat("dd-mm-YYYY", Locale.US)
The following exception gets thrown:
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)
I mean I'm just changing the case right? but is DateFormat really that dumb or am I doing something wrong? or does it have something to do with the Locale I'm using?
Cheers
m and D have their own meaning in SimpleDateFormat pattern:
http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
m   Minute in hour
D   Day in year
But you won't find Y in that table.
You aren't changing only the case, you are changing the meaning of the format :
Y doesn't exist.M stands for Month in year
m stands for Minute in hour
D stands for Day in year
d stands for Day in month
DD-MMM-YYYY and dd-mm-YYYY formats have no meaning.
More info on SimpleDateFormat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With