Hi I am using SimpleDateFormat for parsing and comparing two dates from strings. here is my code
private static int compareDates(String lineFromFile, String givenDate) throws ParseException, IllegalArgumentException
{
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
Date dateFromfile = sdf.parse(tmp);
Date givenDateTime = sdf.parse(givenDate);
if (dateFromfile.equals(givenDateTime))
{
return 0;
}
if (dateFromfile.before(givenDateTime))
{
return 1;
}
return -1;
}
And here is a main method
public static void main(String[] args) {
try
{
int result = compareDates("00:45:44", "09:35:56");
System.out.println(line);
}
catch (ParseException e)
{
e.printStackTrace();
System.out.println("ERROR");
}
}
This works normally when I am passing valid arguments, but ! want to have an exception when passing for example "28:40:04", now I have an exceptions only when passing as an argument string containing letters.