MonthDay isBefore() Method in Java with Examples
isBefore() method of the MonthDay class used to check if this MonthDay is before the MonthDay passed as parameter or not. This method returns a boolean value showing the same.
Syntax:
public boolean isBefore(MonthDay other)
Parameters: This method accepts one parameter other which is the other month-day to compare to.
Return value: This method returns true if this MonthDay is before the specified MonthDay else it returns false.
Below programs illustrate the isBefore() method:
Program 1:
// Java program to demonstrate // MonthDay.isBefore() method import java.time.*; public class GFG { public static void main(String[] args) { // create a MonthDay object MonthDay month = MonthDay.parse( "--10-12" ); // create other MonthDay object MonthDay othermonth = MonthDay.parse( "--11-12" ); // apply isBefore() method boolean value = month.isBefore(othermonth); // print instance System.out.println( "monthday:" + month + " is before monthday:" + othermonth + " = " + value); } } |
monthday:--10-12 is before monthday:--11-12 = true
Program 2:
// Java program to demonstrate // MonthDay.isBefore() method import java.time.*; public class GFG { public static void main(String[] args) { // create a MonthDay object MonthDay month = MonthDay.parse( "--10-12" ); // create other MonthDay object MonthDay othermonth = MonthDay.parse( "--09-12" ); // apply isBefore() method boolean value = month.isBefore(othermonth); // print instance System.out.println( "monthday:" + month + " is before monthday:" + othermonth + " = " + value); } } |
monthday:--10-12 is before monthday:--09-12 = false
References: https://docs.oracle.com/javase/10/docs/api/java/time/MonthDay.html#isBefore(java.time.MonthDay)
Recommended Posts:
- YearMonth isBefore() method in Java with Examples
- Instant isBefore() method in Java with Examples
- LocalTime isBefore() method in Java with Examples
- ChronoZonedDateTime isBefore() method in Java with Examples
- OffsetDateTime isBefore() method in Java with examples
- ChronoLocalDate isBefore() method in Java with Examples
- Year isBefore() method in Java with Examples
- LocalDate isBefore() method in Java with Examples
- OffsetTime isBefore() method in Java with examples
- LocalDateTime isBefore() method in Java with Examples
- ChronoLocalDateTime isBefore() method in Java with Examples
- MonthDay get() method in Java with Examples
- MonthDay with() Method in Java with Examples
- MonthDay from() method in Java with Examples
- MonthDay isSupported() 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.