LocalTime类的isAfter()方法用于检查此LocalTime时间轴位置是否在LocalTime作为参数传递之后。如果此LocalTime时间轴位置在LocalTime作为参数传递之后,则该方法将返回true或false。比较是基于瞬时的时间线位置。
用法:
public boolean isAfter(LocalTime other)
参数:此方法接受一个参数other,该参数是要比较的另一个LocalTime对象。它不能为空。
返回值:如果此时间在指定时间之后,则此方法返回true,否则返回false。
以下示例程序旨在说明isAfter()方法:
示例1:
// Java program to demonstrate
// LocalTime.isAfter() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a LocalTime object
LocalTime time1
= LocalTime.parse("19:34:50.63");
// create other LocalTime
LocalTime time2
= LocalTime.parse("23:14:00.63");
// print instances
System.out.println("LocalTime 1: " + time1);
System.out.println("LocalTime 2: " + time2);
// check if LocalTime is after LocalTime
// using isAfter()
boolean value = time1.isAfter(time2);
// print result
System.out.println("Is LocalTime1 after LocalTime2: "
+ value);
}
}
输出:
LocalTime 1: 19:34:50.630 LocalTime 2: 23:14:00.630 Is LocalTime1 after LocalTime2: false
示例2:
// Java program to demonstrate
// LocalTime.isAfter() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a LocalTime object
LocalTime time1
= LocalTime.parse("23:59:11.98");
// create other LocalTime
LocalTime time2
= LocalTime.parse("10:24:53.21");
// print instances
System.out.println("LocalTime 1: " + time1);
System.out.println("LocalTime 2: " + time2);
// check if LocalTime is after LocalTime
// using isAfter()
boolean value = time1.isAfter(time2);
// print result
System.out.println("Is LocalTime1 after LocalTime2: "
+ value);
}
}
输出:
LocalTime 1: 23:59:11.980 LocalTime 2: 10:24:53.210 Is LocalTime1 after LocalTime2: true
参考: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#isAfter(java.time.LocalTime)
相关用法
- Java OffsetTime isAfter()用法及代码示例
- Java ChronoLocalDate isAfter()用法及代码示例
- Java ChronoZonedDateTime isAfter()用法及代码示例
- Java Instant isAfter()用法及代码示例
- Java LocalDateTime isAfter()用法及代码示例
- Java ChronoLocalDateTime isAfter()用法及代码示例
- Java MonthDay isAfter()用法及代码示例
- Java OffsetDateTime isAfter()用法及代码示例
- Java LocalDate isAfter()用法及代码示例
- Java YearMonth isAfter()用法及代码示例
- Java Year isAfter()用法及代码示例
- Java LocalTime from()用法及代码示例
- Java LocalTime with()用法及代码示例
- Java LocalTime plus()用法及代码示例
- Java LocalTime get()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 LocalTime isAfter() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。