- 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
Instant isAfter() method in Java
It can be checked if a particular Instant object is after the other Instant object in a timeline using the isAfter() method in the Instant class in Java. This method requires a single parameter i.e. the Instant object that is to be compared. It returns true if the Instant object is after the other Instant object and false otherwise.
A program that demonstrates this is given as follows
Example
import java.time.*; import java.time.temporal.ChronoUnit; public class Demo { public static void main(String[] args) { Instant i1 = Instant.parse("2019-01-13T16:10:35.00Z"); Instant i2 = Instant.parse("2019-01-13T11:19:28.00Z"); boolean flag = i1.isAfter(i2); System.out.println("Instant object i1 is: " + i1); System.out.println("Instant object i2 is: " + i2); if(flag) System.out.println("
Instant object i1 is after Instant object i2"); else System.out.println("
Instant object i1 is before Instant object i2"); } }
Output
Instant object i1 is: 2019-01-13T16:10:35Z Instant object i2 is: 2019-01-13T11:19:28Z Instant object i1 is after Instant object i2
Now let us understand the above program.
The two instant objects i1 and i2 are displayed. It is checked if the Instant object i1 is after the Instant object i2 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:
Instant i1 = Instant.parse("2019-01-13T16:10:35.00Z"); Instant i2 = Instant.parse("2019-01-13T11:19:28.00Z"); boolean flag = i1.isAfter(i2); System.out.println("Instant object i1 is: " + i1); System.out.println("Instant object i2 is: " + i2); if(flag) System.out.println("
Instant object i1 is after Instant object i2"); else System.out.println("
Instant object i1 is before Instant object i2");
- Related Articles
- LocalTime isAfter() method in Java
- MonthDay isAfter() Method in Java
- LocalDate isAfter() method in Java
- LocalDateTime isAfter() method in Java
- Instant minusMillis() method in Java
- Instant minusNanos() method in Java
- Instant until() Method in Java
- Instant plus() method in Java
- Instant minus() method in Java
- Instant isSupported() method in Java
- Instant truncatedTo() method in Java
- Instant parse() method in Java
- Instant toString() method in Java
- Instant range() method in Java
- Instant get() method in Java

Advertisements