Java中Year类的isBefore()方法用于检查当前的YearMonth对象是否在指定为该方法的参数YearMonth之前。
用法:
public boolean isBefore(Year otherYearMonth)
参数:它接受单个参数otherYearMonth,它将与当前YearMonth对象进行比较。
返回值:如果此YearMonth对象的值在指定为方法参数的YearMonth对象的值之前,则返回布尔True值,否则返回False。
以下程序说明了Java中的YearMonth.isBefore()方法:
示例1::
// Program to illustrate the isBefore() method
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
// Create first Year object
YearMonth yearMonth1
= YearMonth.of(2018, 3);
// Create second Year object
YearMonth yearMonth2
= YearMonth.of(1997, 4);
// Check if this year-month object's value is
// before the specified Year-month or not
System.out.println(yearMonth1
.isBefore(yearMonth2));
}
}
输出:
false
示例2::
// Program to illustrate the isBefore() method
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
// Create first Year object
YearMonth yearMonth1
= YearMonth.of(1997, 3);
// Create second Year object
YearMonth yearMonth2
= YearMonth.of(2018, 4);
// Check if this year-month object's value is
// before the specified Year-month or not
System.out.println(yearMonth1
.isBefore(yearMonth2));
}
}
输出:
true
参考: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#isBefore-java.time.YearMonth-
相关用法
- Java OffsetDateTime isBefore()用法及代码示例
- Java LocalTime isBefore()用法及代码示例
- Java LocalDate isBefore()用法及代码示例
- Java LocalDateTime isBefore()用法及代码示例
- Java OffsetTime isBefore()用法及代码示例
- Java ChronoLocalDate isBefore()用法及代码示例
- Java ChronoZonedDateTime isBefore()用法及代码示例
- Java Year isBefore()用法及代码示例
- Java Instant isBefore()用法及代码示例
- Java ChronoLocalDateTime isBefore()用法及代码示例
- Java MonthDay isBefore()用法及代码示例
- Java YearMonth until()用法及代码示例
- Java YearMonth with()用法及代码示例
- Java YearMonth withYear()用法及代码示例
- Java YearMonth range()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 YearMonth isBefore() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。