提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用Date类的boolean before(Date anotherDate)方法检查日期是否早于指定日期
/* from N o w J a v a . c o m - 时代Java */ import java.util.Date; public class Main { public static void main(String[] args) { Date d1 = new Date(); try{ Thread.sleep(10); }catch(Exception e){ } Date d2 = new Date(); System.out.println("First Date : " + d1); System.out.println("Second Date : " + d2); System.out.println("Is first date before second ? : " + d1.before(d2)); } }