I try to convert string to date on java. I read and try the example from this website "Java Date and Calendar examples" but I still cannot compile and run it.
This is my code.
package javaapplication5;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class JavaApplication5 {
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
String dateInString = "31-08-1982 10:20:56";
Date date = sdf.parse(dateInString);
System.out.println(date);
}
}
And I got this error.
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unreported exception java.text.ParseException; must be caught or declared to be thrown
What I missing or do it wrong? Thank you for help.