JAVA 两个日期的比较

1.使用after或before

注意是import java.util.Date;

  1)日期相同的时候

        Date date = new Date(2016,9,6);
        Date date2 = new Date(2016,9,6);
        System.out.println(date.before(date2));//false
        System.out.println(date.after(date2));//false

 

 2)日期1小于日期2

        Date date = new Date(2016,9,5);
        Date date2 = new Date(2016,9,6);
        System.out.println(date.before(date2));//true
        System.out.println(date.after(date2));//false

 

 3)日期1大于日期2

        Date date = new Date(2016,9,7);
        Date date2 = new Date(2016,9,6);
        System.out.println(date.before(date2));//false
        System.out.println(date.after(date2));//true

 

posted on 2016-09-07 10:59  laugher_ccc  阅读(3555)  评论(0编辑  收藏  举报

导航