Java 中的 OffsetDateTime isAfter()方法,带示例
原文:https://www . geesforgeks . org/offsetdatetime-is after-method-in-Java-with-examples/
Java 中 OffsetDateTime 类的isaafter()方法检查这个日期是否在指定的日期时间之后,如果是,返回 true。
语法:
public boolean isAfter(OffsetDateTime other)
参数:该方法接受单个参数其他,检查该日期时间是否在另一个日期时间之后。
返回值:如果在另一个日期时间之后,则返回真,否则返回假。
以下程序说明了 isAfter() 方法:
程序 1:
// Java program to demonstrate the isAfter() method
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
public class GFG {
public static void main(String[] args)
{
// Parses the date1
OffsetDateTime date1
= OffsetDateTime
.parse("2018-12-12T13:30:30+05:00");
// Parses the date2
OffsetDateTime date2
= OffsetDateTime
.parse("2018-12-12T13:30:30+05:00");
// Prints both dates
System.out.println("Date1: "
+ date1);
System.out.println("Date2: "
+ date2);
// Compare both
System.out.println("Is Date1 after Date2? "
+ date1.isAfter(date2));
}
}
输出:
Date1: 2018-12-12T13:30:30+05:00
Date2: 2018-12-12T13:30:30+05:00
Is Date1 after Date2? false
程序二 :
// Java program to demonstrate the isAfter() method
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
public class GFG {
public static void main(String[] args)
{
// Parses the date1
OffsetDateTime date1
= OffsetDateTime
.parse("2018-12-12T13:30:30+05:00");
// Parses the date2
OffsetDateTime date2
= OffsetDateTime
.parse("2015-12-12T13:30:30+05:00");
// Prints both dates
System.out.println("Date1: "
+ date1);
System.out.println("Date2: "
+ date2);
// Compare both
System.out.println("Is Date1 after Date2? "
+ date1.isAfter(date2));
}
}
输出:
Date1: 2018-12-12T13:30:30+05:00
Date2: 2015-12-12T13:30:30+05:00
Is Date1 after Date2? true
版权属于:月萌API www.moonapi.com,转载请注明出处