1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| private Date parseStringToDate(String s) {
Date d = null;
if (s.contains("-")){
try {
String dayRangeFormat = "dd-dd MMM yyyy";
DateFormat dayRangeDateFormat = new SimpleDateFormat(dayRangeFormat, Locale.US);
d = dayRangeDateFormat.parse(s);
} catch (ParseException e) {
try {
String monthDayRangeFormat = "MMM dd - MMM dd yyyy";
DateFormat monthDayDateFormat = new SimpleDateFormat(monthDayRangeFormat, Locale.US);
d = monthDayDateFormat.parse(s);
} catch (ParseException e1) {
try {
String dayMonthRangeFormat = "dd MMM - dd MMM yyyy";
DateFormat dayMonthRangeDateFormat = new SimpleDateFormat(dayMonthRangeFormat, Locale.US);
d = dayMonthRangeDateFormat.parse(s);
} catch (ParseException e2) {
try {
String dayMonthRangeFormat2 = "dd MMM- dd MMM yyyy";
DateFormat dayMonthRangeDateFormat2 = new SimpleDateFormat(dayMonthRangeFormat2, Locale.US);
d = dayMonthRangeDateFormat2.parse(s);
} catch (ParseException e3) {
try {
String nonsenseRangeFormat = "dd-dd yyyy yyyy";
DateFormat nonsenseRangeDateFormat = new SimpleDateFormat(nonsenseRangeFormat, Locale.US);
d = nonsenseRangeDateFormat.parse(s);
} catch (ParseException e4) {
//throw new RuntimeException(e4);
System.err.println(e4);
}
}
}
}
}
}
else{
try {
d = defaultDateFormat.parse(s);
} catch (ParseException e) {
try {
d = alternativeDateFormat.parse(s);
} catch (ParseException e1) {
throw new RuntimeException(e1);
}
}
}
return d; |