static public Date parseDate(String s) throws ParseException {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    return format.parse(s);
  }

解决方案 »

  1.   

    public static Date stringToDate(String s, String pattern) throws
          ParseException {
        try {
          Date date;
          SimpleDateFormat formatter = new SimpleDateFormat(pattern);
          date = formatter.parse(s);
          return date;
        }
        catch (ParseException e) {
          throw e;
        }
      }
    调用stringToDate("2002-08-09","yyyy-MM-dd")
      

  2.   

    Date date = new java.text.SimpleDateFormat("yyyy-MM-dd").format("2002-02-09");
      

  3.   

    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");