String str="2010-12-25 12:23:40",要把这个字符串变成20101225,你有多少种处理方式?
麻烦各位高手给出具体代码

解决方案 »

  1.   

    String str="2010-12-25 12:23:40".replace("-","").substring(0,10);办法多的是 这个简单就用简单的吧!
      

  2.   


    public   static   void   main(String[]args) 

       String str="2010-12-25 12:23:40"; 
       System.out.println(format1(str));
       System.out.println(format2(str));

    public static String format1(String str){
        return str.substring(0,10).replace("-","");
    }
    public static String format2(String str){
        java.text.SimpleDateFormat df=new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        java.util.Date temp = df.parse(str, new java.text.ParsePosition(0));
        df=new java.text.SimpleDateFormat("yyyyMMdd");
        return df.format(temp);
    }
      

  3.   

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HHmmss");
         Date date = sdf.parse("2010-12-25 12:23:40");
         sdf = new SimpleDateFormat("yyyyMMdd");
         System.out.println(sdf.format(date));String str="2010-12-25 12:23:40";
    System.out.println(str.split(" ")[0].replaceAll("-",""));没有ide你自己试试吧。