java 比较两个时间大小

Date d1 = new Date(System.currentTimeMillis()-1000);
Date d2 = new Date(System.currentTimeMillis());
System.out.println(d1.compareTo(d2));

  java util date 自带了compareTo 功能,可直接比较大小。

  前者大于后者 返回大于0 反之小于0。
  

  LocatDateTime 同理

posted @ 2017-07-11 10:33  蓝色枫梦  阅读(26087)  评论(0编辑  收藏  举报