当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java ChronoLocalDate isAfter()用法及代码示例


Java中ChronoLocalDate接口的isAfter()方法检查此日期是否在指定的日期之后,并返回一个说明该日期的布尔值。

用法

public boolean isAfter(ChronoLocalDate date2)

参数:此方法接受另一个要与之比较的日期的单个强制性参数date2,但不为null。


返回值:如果此日期晚于指定日期,则该函数返回true。

以下程序说明了Java中ChronoLocalDate的isAfter()方法:

程序1

// Program to illustrate the isAfter() method 
  
import java.util.*; 
import java.time.*; 
import java.time.chrono.*; 
  
public class GfG { 
    public static void main(String[] args) 
    { 
        // Parses the first date 
        ChronoLocalDate dt1 
            = LocalDate.parse("2018-11-27"); 
  
        // Parses the second date 
        ChronoLocalDate dt2 
            = LocalDate.parse("2017-11-27"); 
  
        // Check if the specified date 
        // is after this date 
        System.out.println(dt1.isAfter(dt2)); 
    } 
}
输出:
true

程序2

// Program to illustrate the isAfter() method 
  
import java.util.*; 
import java.time.*; 
import java.time.chrono.*; 
  
public class GfG { 
    public static void main(String[] args) 
    { 
        // Parses the first date 
        ChronoLocalDate dt1 
            = LocalDate.parse("2018-11-27"); 
  
        // Parses the second date 
        ChronoLocalDate dt2 
            = LocalDate.parse("2019-11-27"); 
  
        // Check if the specified date 
        // is after this date 
        System.out.println(dt1.isAfter(dt2)); 
    } 
}
输出:
false

参考: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoLocalDate.html#isAfter-java.time.chrono.ChronoLocalDate-



相关用法


注:本文由纯净天空筛选整理自Kirti_Mangal大神的英文原创作品 ChronoLocalDate isAfter() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。