programming-examples/java/Servlets_Session_Swing_Util/Comparing two dates.java
2019-11-15 12:59:38 +01:00

27 lines
685 B
Java

Comparing two dates
import java.util.*;
import java.text.*;
public class CompareDates {
public static void main(String[] args) throws ParseException {
DateFormat df = new SimpleDateFormat ("yyyy-MM-dd");
// Get Date 1
Date d1 = df.parse(args[0]);
// Get Date 2
Date d2 = df.parse(args[1]);
String relation;
if (d1.equals(d2))
relation = "the same date as";
else if (d1.before(d2))
relation = "before";
else
relation = "after";
System.out.println(d1 + " is " + relation + ' ' + d2);
}
}