Java Date after()
Java Date类的
after()方法测试日期是否在指定的日期之后。
语法:
public boolean after(Date when)
参数
when-日期
返回
它返回布尔值true(如果此日期晚于指定日期)。否则,返回false。
Exception
如果when为null,则将引发NullPointerException。
示例1
import java.util.Date;
public class JavaDateAfterExample1 {
public static void main(String[] args) {
Date d=new Date(2018,9,21);
Date d2=new Date(1997,3,10);
System.out.println("Date 'd' is after Date 'd2' : "+d.after(d2));
}
}
输出:
Date 'd' is after Date 'd2' : true
示例2
import java.util.Date;
public class JavaDateAfterExample2 {
public static void main(String[] args) {
Date d=new Date(1997,3,10);
Date d2=new Date(2018,9,21);
System.out.println("Date 'd' is after Date 'd2' : "+d.after(d2));
}
}
输出:
Date 'd' is after Date 'd2' : false