Date的after()函数,如果在之后返回true,否则返回false.

解决方案 »

  1.   

    用SimpleDateFormat将字符串转化成日期型,再转化成Calendar,用compareTo比较.
      

  2.   

    String startDate = "2003-10-12";
    String endDate = "2004-10-12";
    SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
    Date a = dateFormat.parse(startDate); 
    Date b = dateFormat.parse(endDate);if (a.getTime()-b.getTime()>0)
        System.out.println("startDate 大于 endDate");
    else
        System.out.println("startDate 小于 endDate");
      

  3.   

    totodo的方法功能最强大,可以比较相差的天数
      

  4.   

    String startDate = "2003-10-12";
    String endDate = "2004-10-12";
    如果你的日期格式比较规范,而你又只是想比较日期的先后
    你不访直接把它们当做普通的字符串来比较
      

  5.   

    如果格式允许,用string来比较最简单
      

  6.   

    哟,支持直接String比较!
    会很简单!
      

  7.   

    Date类直接提供after和before函数
    想要相差的天数就用Calendar类
      

  8.   

    转换成标准格式数字字符串比较
    或者
    采用专程成毫秒比较
    或者
    采用API里面的方法比较
      

  9.   

    private int getPeriod(String begin, String end)
    {
        int[] anResult = new int[2] ;
        java.util.Date oBegin = ( new SimpleDateFormat("yyyyMMdd") ).parse(begin, new ParsePosition(0)) ;
        java.util.Date oEnd   = ( new SimpleDateFormat("yyyyMMdd") ).parse(end, new ParsePosition(0)) ;
        long periodMilli = oEnd.getTime() - oBegin.getTime() ;
        int  period      = (new Long(periodMilli / (1000 * 3600 * 24))).intValue() ;
        return period ;
    }