java.text.ParseException: Unparseable date: "2007-05-22T16:00:00.000Z"代码如下:
String text  = ((org.apache.axiom.om.OMElement)child).getText();
                 if( !text.trim().equals(""))
                 {
                 DateFormat dateFormat =new SimpleDateFormat("MM/dd/yyyy");
                 dateFormat.setLenient(false);
                 try {
java.util.Date date = dateFormat.parse(text);
book.setPublishDate(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
                 }
text的值="2007-05-22T16:00:00.000Z",其实我只要它能够有year,month,day就可以了,后面的hh,mm,ss都不需要。
求教

解决方案 »

  1.   

    String text  = ((org.apache.axiom.om.OMElement)child).getText();
        if( !text.trim().equals(""))
              {          text = text.subString(0,10);          DateFormat dateFormat =new SimpleDateFormat("MM/dd/yyyy");
               dateFormat.setLenient(false);
              try { java.util.Date date = dateFormat.parse(text); book.setPublishDate(date);
    } catch (ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
      

  2.   

    String text  = "2007-05-22T16:00:00.000Z";
        if( !text.trim().equals(""))
              {          text = text.substring(0,10);          java.text.SimpleDateFormat
     dateFormat =new java.text.SimpleDateFormat
    ("yyyy-MM-dd");
               //dateFormat.setLenient(false);
              try {
        java.util.Date date = dateFormat.parse(text);
    //book.setPublishDate(date);
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }不知道这样符不符合你的要求
      

  3.   

    用simpleDateFormat可以轻松搞定啊
      

  4.   

    thank you, it works correctly.