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-
相關用法
- Java LocalDateTime isAfter()用法及代碼示例
- Java LocalDate isAfter()用法及代碼示例
- Java OffsetDateTime isAfter()用法及代碼示例
- Java Instant isAfter()用法及代碼示例
- Java MonthDay isAfter()用法及代碼示例
- Java Year isAfter()用法及代碼示例
- Java LocalTime isAfter()用法及代碼示例
- Java ChronoLocalDateTime isAfter()用法及代碼示例
- Java ChronoZonedDateTime isAfter()用法及代碼示例
- Java ChronoLocalDate isAfter()用法及代碼示例
- Java YearMonth isAfter()用法及代碼示例
- Java OffsetTime from()用法及代碼示例
- Java OffsetTime plus()用法及代碼示例
- Java OffsetTime now()用法及代碼示例
- Java OffsetTime with()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 OffsetTime isAfter() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。