LocalTime isAfter() method in Java with Examples
The isAfter() method of a LocalTime class is used to check if this LocalTime timeline position is after the LocalTime passed as parameter or not. If this LocalTime timeline position is after the LocalTime passed as a parameter then the method will return true else false. The comparison is based on the time-line position of the instants.
Syntax:
public boolean isAfter(LocalTime other)
Parameters: This method accepts a single parameter other which is the other LocalTime object to compare to. It should not be null.
Return value: This method returns true if this time is after the specified time, else false.
Below programs illustrate the isAfter() method:
Program 1:
// Java program to demonstrate // LocalTime.isAfter() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime object LocalTime time1 = LocalTime.parse("19:34:50.63"); // create other LocalTime LocalTime time2 = LocalTime.parse("23:14:00.63"); // print instances System.out.println("LocalTime 1: " + time1); System.out.println("LocalTime 2: " + time2); // check if LocalTime is after LocalTime // using isAfter() boolean value = time1.isAfter(time2); // print result System.out.println("Is LocalTime1 after LocalTime2: " + value); } } |
LocalTime 1: 19:34:50.630 LocalTime 2: 23:14:00.630 Is LocalTime1 after LocalTime2: false
Program 2:
// Java program to demonstrate // LocalTime.isAfter() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalTime object LocalTime time1 = LocalTime.parse("23:59:11.98"); // create other LocalTime LocalTime time2 = LocalTime.parse("10:24:53.21"); // print instances System.out.println("LocalTime 1: " + time1); System.out.println("LocalTime 2: " + time2); // check if LocalTime is after LocalTime // using isAfter() boolean value = time1.isAfter(time2); // print result System.out.println("Is LocalTime1 after LocalTime2: " + value); } } |
LocalTime 1: 23:59:11.980 LocalTime 2: 10:24:53.210 Is LocalTime1 after LocalTime2: true
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#isAfter(java.time.LocalTime)
Recommended Posts:
- Instant isAfter() method in Java with Examples
- OffsetDateTime isAfter() method in Java with examples
- ChronoLocalDateTime isAfter() method in Java with Examples
- OffsetTime isAfter() method in Java with examples
- MonthDay isAfter() Method in Java with Examples
- ChronoZonedDateTime isAfter() method in Java with Examples
- LocalDateTime isAfter() method in Java with Examples
- YearMonth isAfter() method in Java with Examples
- Year isAfter() method in Java with Examples
- LocalDate isAfter() method in Java with Examples
- ChronoLocalDate isAfter() method in Java with Examples
- LocalTime plus() method in Java with Examples
- LocalTime with() Method in Java with Examples
- LocalTime get() method in Java with Examples
- LocalTime from() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

