OffsetTime isBefore() method in Java with examples
The isBefore() method of OffsetTime class in Java formats checks if the passed time is before the specified time in the parameter.
Syntax:
public boolean isBefore(OffsetTime other)
Parameter: This method accepts a single mandatory parameter other which specifies the time to be compared with.
Return Value: It returns true if the date is before the passed date, else it return false.
Below programs illustrate the isBefore() method:
Program 1 :
// Java program to demonstrate the isBefore() method import java.time.OffsetTime; public class GFG { public static void main(String[] args) { // Parses the time OffsetTime time1 = OffsetTime.parse("15:30:30+07:00"); // Parses the time OffsetTime time2 = OffsetTime.parse("15:20:30+07:00"); // gets the time1 System.out.println("time1: " + time1); // gets the time2 System.out.println("time1: " + time2); System.out.println("time1 is before time2: " + time1.isBefore(time2)); } } |
time1: 15:30:30+07:00 time1: 15:20:30+07:00 time1 is before time2: false
Program 2 :
// Java program to demonstrate the isBefore() method import java.time.OffsetTime; public class GFG { public static void main(String[] args) { // Parses the time OffsetTime time1 = OffsetTime.parse("15:30:30+07:00"); // Parses the time OffsetTime time2 = OffsetTime.parse("15:30:30+07:00"); // gets the time1 System.out.println("time1: " + time1); // gets the time2 System.out.println("time1: " + time2); System.out.println("time1 is before time2: " + time1.isBefore(time2)); } } |
time1: 15:30:30+07:00 time1: 15:30:30+07:00 time1 is before time2: false
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#isBefore-java.time.OffsetTime-
Recommended Posts:
- ChronoLocalDateTime isBefore() method in Java with Examples
- Year isBefore() method in Java with Examples
- YearMonth isBefore() method in Java with Examples
- MonthDay isBefore() Method in Java with Examples
- ChronoZonedDateTime isBefore() method in Java with Examples
- LocalTime isBefore() method in Java with Examples
- LocalDate isBefore() method in Java with Examples
- OffsetDateTime isBefore() method in Java with examples
- LocalDateTime isBefore() method in Java with Examples
- ChronoLocalDate isBefore() method in Java with Examples
- Instant isBefore() method in Java with Examples
- OffsetTime get() method in Java with examples
- OffsetTime from() method in Java with examples
- OffsetTime with() Method in Java with Examples
- OffsetTime now() 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.



