Studytonight is now part of the GUVI universe. Explore GUVI →
🤩 New Cool Developer Tools for you. Explore →
FREE JavaScript Video Series Start Learning →
Signup/Sign In
Tests
MCQs to test your knowledge.
Compilers
Compilers to execute code in browser.
Index
LAST UPDATED: JUNE 15, 2020

Java LocalDate isAfter() Method With Examples

The isAfter() method is used to check if this date is after the specified date. We can use it to check whether a date is older to the specified date or not.

This method belongs to LocalDate class which is located into java.time package. Syntax of the method is given below.

Syntax

public boolean isAfter(ChronoLocalDate other)

Parameters:

It takes a single parameter of ChronoLocalDate type.

Returns:

It returns a boolean value either true or false.

Example

Lets take an example to check if a date is older than the other specified date. Here we have two dates and checking for both using isAfter() mehtod.

import java.time.LocalDate;
public class Demo { 
	public static void main(String[] args){ 
		
		// Take a date
		LocalDate localDate1 = LocalDate.of(2018, 2, 20);
		// Take another date
		LocalDate localDate2 = LocalDate.of(2018, 8, 10);
		// Displaying date
		System.out.println("is "+localDate1+" older than "+localDate2+": "+localDate1.isAfter(localDate2));
		// Displaying date
		System.out.println("is "+localDate2+" older than "+localDate1+": "+localDate2.isAfter(localDate1));
	}
} 


is 2018年02月20日 older than 2018年08月10日: false
is 2018年08月10日 older than 2018年02月20日: true

Example:

Take a scenario where two dates are same then using isAfter() method will return always false.

import java.time.LocalDate;
public class Demo { 
	public static void main(String[] args){ 
		
		// Take a date
		LocalDate localDate1 = LocalDate.of(2018, 2, 20);
		// Take another date
		LocalDate localDate2 = LocalDate.of(2018, 2, 20);
		// Displaying date
		System.out.println("is "+localDate1+" older than "+localDate2+": "+localDate1.isAfter(localDate2));
		// Displaying date
		System.out.println("is "+localDate2+" older than "+localDate1+": "+localDate2.isAfter(localDate1));
	}
} 


is 2018年02月20日 older than 2018年02月20日: false
is 2018年02月20日 older than 2018年02月20日: false

Live Example:

Try with a live example, execute the code instantly with our power Online Java Compiler.

[フレーム]



About the author:
I am a 3rd-year Computer Science Engineering student at Vellore Institute of Technology. I like to play around with new technologies and love to code.

Learn to Code
Learn and practice coding side-by-side.
NEW
C language Course
115+ coding exercises
Javascript Course
85+ coding exercises

AltStyle によって変換されたページ (->オリジナル) /