DateFormat
parse(String text,ParsePosition pos)
返回date再两个时间一比就可以了

解决方案 »

  1.   

    public boolean compareLapseTime(String dateString){
            String currentDate = this.getCurrentSystemTime();
            DateFormat df = DateFormat.getInstance();
            try{
                if(df.parse(currentDate).after(df.parse(dateString))){
                    return true;
                }else{
                }
            }catch(ParseException e){
            }
            return false;
        }
    这怎么不行的,try执行不到???
      

  2.   

    java.text.ParseException: Unparseable date: "2002-10-30 01:31:23"怎样才能parse?
      

  3.   

    SimpleDateFormat formatter     = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");String currentDate = this.getCurrentSystemTime();
            try{
                if(formatter.parse(currentDate).after(formatter.parse(dateString))){
                    return true;
                }
            }catch(ParseException e){
            }
            return false;
        
      

  4.   

    对于你这样的字符串,是不是可以简单进行字符串比较,如果字符串大的,那么日期的比较靠前.
    if(str1.compare(str2)>0){}
    else if(str1.compare(str2)>0){
    //}
    else{
     //相等
    }当然,把字符串变换成日期再比较是问题的正解.特别是如果日期是"July 6 2002"或者其他什么形式的字符串的时候,必须用date来完成.当然,并不是所有任意的字符串都可以转换成date.但是对于你这样的字符串,全部是数字表示的,我想也许可以用string直接比较吧.
      

  5.   

    上面的else if写错了.应该是"<".另外,这样要求每个字符串必须相等长度,比如应该是写成2002-07-06而不是2002-7-6,否则字符串比较也行不同.
      

  6.   

    还有一个问题:现在还有一个同样格式的字符串,怎么将它与currentDate相加起来,然后也是得到同样格式的字符串?
      

  7.   

    因为现在给出一个时间:fixtime = "2-2-2 19:12:12",格式同上,在程序中,dateString为起始时间,当dateString 再加上 fixtime 是超过当前系统时间 currentDate 的话,返回true!所以要将 fixtime 与 dataString 的时间相加!
      

  8.   

    做出来啦,最后用GregorianCalendar实现!Thanks all!