SimpleDateFormatString str= "20020201";
Date a=null;
SimpleDateFormat s = new SimpleDateFormat("yyyyMMdd");
try 
{
a= s.parse(str);
}
catch (Exception ex) {}

解决方案 »

  1.   

    ava.text.SimpleDateFormat f = new java.text.SimpleDateFormat("yyyy-mm-dd");
    Date d1 = f.parse("2222-01-11");
      

  2.   

    转换时的格式必须对应,下面是两种格式的转换,你看看,自己换成你需要的
    String s1="2002-1-1 00:00:00";
    String s2="2002-1-1";
    java.text.SimpleDateFormat sdf1=new java.text.SimpleDateFormat("yyyy-MM-dd HH;MM;ss");
    java.text.SimpleDateFormat sdf2=new java.text.SimpleDateFormat("yyyy-MM-dd");
    java.util.Date d1=null,d2=null;
    try{
    d1=sdf1.parse(s1);
    d2=sdf2.parse(s2);
    }catch(Exception e){
    System.out.println(e.toString());
    }
      

  3.   

    根本不需要转换,例如:myDate为字符串型,DateTime为数据库中日期型字段。
    "insert into card(DateTime) values("+myDate+")"
      

  4.   

    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("M/dd/yyyy hh:mm:ss a",java.util.Locale.US);
    java.util.Date d = sdf.parse("5/13/2003 10:31:37 AM");  
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String mDateTime=formatter.format(d);
      

  5.   

    String wux="20030614";
        GregorianCalendar a=new GregorianCalendar();
        a.set(Integer.parseInt(wux.substring(0,4)),Integer.parseInt(wux.substring(4,6))-1,Integer.parseInt(wux.substring(6)));
        SimpleDateFormat b=new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(b.format(a.getTime()));
      

  6.   

    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyymmdd");
    Date date = sdf.parse("2001111");
      

  7.   

    java提供了进行字符串转化为日期的类SimpleDateFormat他的使用方法和上面几位说的一样String str = ......
    try
    {
        SimpleDateFormat s = new SimpleDateFormat("yyyyMMdd");//这里引号中是你字符串中日期的格式,比如2002-01-13,这里就写成yyyy-MM-dd
        Date a= s.parse(str);
    }
    catch (Exception e) {}