Java Date时间比较大小

String DateStr1 = "2013-10-01 10:10:10";
String DateStr2 = "2013-10-02 11:11:11";

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date dateTime1 = dateFormat.parse(DateStr1);
Date dateTime2 = dateFormat.parse(DateStr2);

System.out.println(dateTime1.compareTo(dateTime2)); 

注:
如果dateTime1大于dateTime2,则返回1;
如果dateTime1等于dateTime2,则返回0;
如果dateTime1小于dateTime2,则返回-1;

源: http://blog.csdn.net/maxracer/article/details/8439937

posted @ 2015-03-14 19:58  vaer  阅读(634)  评论(0编辑  收藏  举报