- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
LocalTime isAfter() method in Java
It can be checked if a particular LocalTime is after the other LocalTime in a timeline using the isAfter() method in the LocalTime class in Java. This method requires a single parameter i.e. the LocalTime object that is to be compared. It returns true if the LocalTime object is after the other LocalTime object and false otherwise.
A program that demonstrates this is given as follows
Example
import java.time.*; public class Main { public static void main(String[] args) { LocalTime lt1 = LocalTime.parse("11:37:12"); LocalTime lt2 = LocalTime.parse("23:15:30"); System.out.println("The LocalTime lt1 is: " + lt1); System.out.println("The LocalTime lt2 is: " + lt2); boolean flag = lt1.isAfter(lt2); if(flag) System.out.println("
LocalTime object lt1 is after LocalTime object lt2"); else System.out.println("
LocalTime object lt1 is before LocalTime object lt2"); } }
output
The LocalTime lt1 is: 11:37:12 The LocalTime lt2 is: 23:15:30 LocalTime object lt1 is before LocalTime object lt2
Now let us understand the above program.
The two LocalTime objects lt1 and lt2 are displayed. It is checked if the LocalTime object lt1 is after the LocalTime object lt2 in the timeline using the isAfter() method. The returned value is displayed using an if statement. A code snippet that demonstrates this is as follows:
LocalTime lt1 = LocalTime.parse("11:37:12"); LocalTime lt2 = LocalTime.parse("23:15:30"); System.out.println("The LocalTime lt1 is: " + lt1); System.out.println("The LocalTime lt2 is: " + lt2); boolean flag = lt1.isAfter(lt2); if(flag) System.out.println("
LocalTime object lt1 is after LocalTime object lt2"); else System.out.println("
LocalTime object lt1 is before LocalTime object lt2");
Advertisements