MAIN.JAVA:
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Scanner; import java.util.Date; public class Main { static String startd; static String endd; public static void main(String[] args) { // your code here Scanner sc = new Scanner(System.in); SimpleDateFormat formatter=new SimpleDateFormat("dd-MM-yyyy-HH:mm:ss"); System.out.println("Enter the stage event start date and end date"); startd = sc.nextLine(); try { Date date = formatter.parse(startd); endd=sc.next(); try{ Date date1 = formatter.parse(endd); System.out.println("Start date:"+formatter.format(date)); System.out.println("End date:"+formatter.format(date1)); }catch (ParseException e) { System.out.println("Input dates should be in the format 'dd-MM-yyyy-HH:mm:ss'"); } }catch (Exception a){ System.out.println("Input dates should be in the format 'dd-MM-yyyy-HH:mm:ss'"); } } }