A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/java-tutorial/util/date/java_date_after.php below:

Website Navigation


Java Date: after() Method - w3resource

Java Date.after() MethodLast update on August 19 2022 21:50:42 (UTC/GMT +8 hours) public boolean after(Date dt)

The after() method is used to check if a given date is after another given date.

Package: java.util

Java Platform: Java SE 8

Syntax:

after(Date dt)

Parameters:

Name Description dt a date

Return Value:
true if and only if the instant represented by this Date object is strictly later than the instant represented by when; false otherwise.

Return Value Type: boolean

Throws:
NullPointerException - if when is null.

Pictorial Presentation of Jave Date after() method:

Example: Java Date.after() Method.

import java.util.*;
public class Main {
   public static void main(String[] args) {

      // create 2 dates
      Date dt1 = new Date(2017, 3, 31);
      Date dt2 = new Date(2017, 5, 14);

      // Check if dt1 is  after dt2
      boolean result = dt1.after(dt2);
      System.out.println("Date1 is after date2: " + result);

      // Check if dt2 is  after dt1
      result = dt2.after(dt1);
      System.out.println("Date2 is after date1: " + result);
   }
}
 

Output:

Date1 is after date2: false
Date2 is after date1: true

Java Code Editor:

Previous:Date Class Methods Home
Next:before Method


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4