import java.util.Date; public class Example1 { public static void main(String[] args) { Date currentDate = new Date(); Date pastDate = new Date(1000000000); // January 12, 1970 - 13:46:40 Date futureDate = new Date(3000000000); // January 13, 1970 - 05:20:00 System.out.println(currentDate.after(pastDate)); // true System.out.println(currentDate.after(futureDate)); // false } }
import java.util.Date; public class Example2 { public static void main(String[] args) { Date date1 = new Date(500000000); // January 8, 1970 - 04:53:20 Date date2 = new Date(1500000000); // January 16, 1970 - 14:40:00 if (date1.after(date2)) { System.out.println("date1 is after date2"); } else { System.out.println("date1 is not after date2"); } } }In this example, we create two Date objects - one on January 8, 1970 at 04:53:20 and another on January 16, 1970 at 14:40:00. We then use an if statement with the after() method to check whether date1 is after date2. Package Library: java.util