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


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

Java格式的OffsetTime类的isAfter()方法检查传递的时间是否在参数中的指定时间之后。

用法:

public boolean isAfter(OffsetTime other)

参数:此方法接受单个强制性参数other,该参数指定要与之比较的时间。


返回值:如果日期晚于传递的日期,则返回true,否则返回false。

以下示例程序旨在说明isAfter()方法:

示例1:

// Java program to demonstrate the isAfter() 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"); 
  
        // prints the time1 
        System.out.println("time1: "
                           + time1); 
  
        // prints the time2 
        System.out.println("time1: "
                           + time2); 
  
        System.out.println("time1 is after time2: "
                           + time1.isAfter(time2)); 
    } 
}
输出:
time1: 15:30:30+07:00
time1: 15:20:30+07:00
time1 is after time2: true

程序2

// Java program to demonstrate the isAfter() 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"); 
  
        // prints the time1 
        System.out.println("time1: "
                           + time1); 
  
        // prints the time2 
        System.out.println("time1: "
                           + time2); 
  
        System.out.println("time1 is after time2: "
                           + time1.isAfter(time2)); 
    } 
}
输出:
time1: 15:30:30+07:00
time1: 15:30:30+07:00
time1 is after time2: false

参考: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#isAfter-java.time.OffsetTime-



相关用法

注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 OffsetTime isAfter() method in Java with examples。非经特殊声明,原始代码版权归原作者所有,本译文的传播和使用请遵循“署名-相同方式共享 4.0 国际 (CC BY-SA 4.0)”协议。