I am getting issues with Date Format. I am using SimpleDateFormat to parse date and using MM/dd/yyyy format to parse date, its working properly with correct input like 11/11/2011 and its returning correct result (Fri Nov 11 00:00:00 IST 2011)
But if we enter 11/11/11 as input then its not working properly (Wed Nov 11 00:00:00 IST 11), nor giving parse error.
public static void main(String[] args) {
String format = "MM/dd/yyyy";
String dt = "11/11/11";
Date date = null;
try {
date = TestDate.parDate(dt, format);
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println(date);
}
public static Date parDate(String value, String dateFormat) throws ParseException {
Date date = null;
date = new SimpleDateFormat(dateFormat).parse(value);
return date;
}