i was trying to convert date in string format to date using DateUtils
. Following are my expected date format,
private static final String[] EXPECTED_DATE_FORMAT = {"yyyy-MM-dd","dd-MM-yyyy","dd-MMM-yyyy",};
And I ran the test against following values,
System.out.println(org.apache.commons.lang.time.DateUtils.parseDate("2019-05-18", EXPECTED_DATE_FORMAT));
System.out.println(org.apache.commons.lang.time.DateUtils.parseDate("18-05-2019", EXPECTED_DATE_FORMAT));
System.out.println(org.apache.commons.lang.time.DateUtils.parseDate("18-May-2019", EXPECTED_DATE_FORMAT));
And I am getting the following result,
Sat May 18 00:00:00 IST 2019
Tue Nov 09 00:00:00 IST 23
Sat May 18 00:00:00 IST 2019
Why the second value "18-05-2019
" is not matching with the format "dd-MM-yyyy
" and get me the same result?
What changes I should support both dd-MM-yyyy
and yyyy-MM-dd
?