Java offsetTime isAfter()方法及示例

Java offsetTime isAfter()方法及示例

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

语法

public boolean isAfter(OffsetTime other)

参数: 该方法接受一个强制参数 , 指定要比较的时间。

返回值: 如果日期在传递的日期之后,则返回真,否则返回假。

下面的程序说明了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-

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程