先用DateFormat转换成Date,再用DateFormat转换成字符串

解决方案 »

  1.   


    import java.text.ParsePosition;
    import java.text.SimpleDateFormat;
    import java.util.Date;public class DateFormat { /**
     * @param args
     */
    public static void main(String[] args) {
    String str = "Mon Jan 04 01:16:11 CST 2010";
            SimpleDateFormat da = new SimpleDateFormat("dd HH:mm:ss z yyyy");
            Date date = da.parse(str, new ParsePosition(8));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
    String currentDateStr = sdf.format(date);
            System.out.println(currentDateStr);
    }
    }
      

  2.   

    这2行改改String str = "Wed Dec 23 17:11:35 2009";
    SimpleDateFormat da = new SimpleDateFormat("dd HH:mm:ss yyyy");
      

  3.   

    Date date = new Date();  //定义一个Date类型对象
    //格式化系统时间
    DateFormat dateFormat = 
    DateFormat.getDateInstance(DateFormat.FULL);
    //返回一个格式化好的时间对象date
    return dateFormat.format(date);
      

  4.   


    public class test {
    public static void main(String arg[]) {
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.US);
    SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    try {
    System.out.println(sdf2.format(sdf.parse("Wed Dec 23 17:11:35 2009")));
    } catch (ParseException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }自己搞定了,散分