我的SimpleDateFormat
不断投掷ParseException
。我无法让它真正进入try块,它只是直接进入我的捕获。知道我的代码有什么问题吗?
public static String getEventDate() throws ParseException {
System.out.println("When is the date of your event? (dd/MM/yyyy)");
String date = in.nextLine();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date eventDate = null;
try {
eventDate = dateFormat.parse(date);
} catch (ParseException e) {
System.out.println("Error in date format");
}
String finalDate = dateFormat.format(eventDate);
return finalDate;
}
public static void main(String[] args) throws ParseException {
Event event = getEventInfo();
System.out.println(event);
}
public static Event getEventInfo() throws ParseException {
String eventType = getEventType();
String eventDate = getEventDate();
Event event = new Event(eventType, eventDate);
return event;
}