得到的时间是“Thu Jun 06 1985 00:00:00 GMT+0800 (中国标准时间)” 这样的字符串        怎么改成yyyy-MM-dd的格式啊?

解决方案 »

  1.   

    SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");format.format(字符串);
      

  2.   

    如果是字符串,你就要自己写一个程序。拆分这个字符串,然后构造一个Calendar.然后用SimpleDateFormat明白吗?
      

  3.   

    “Thu Jun 06 1985 00:00:00 GMT+0800 (中国标准时间)”已经是字符串了,很难了,除非自己解析。
    正确的做法应该是拿到时间对象,再用SimpleDateFormat
      

  4.   

    SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");format.format("这是是日期");
    出来的就是你想要的格式了。
      

  5.   

    new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss' GMT'Z' (中国标准时间)'",Locale.ENGLISH);
      

  6.   

    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class Test { /**
     * @param args
     */
    public static void main(String[] args) {
    SimpleDateFormat formart = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date("Thu Jun 06 1985 00:00:00 GMT+0800");
    System.out.println(formart.format(date));
    }}結果:1985-06-06
      

  7.   

    SimpleDateFormat formart = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date("Thu Jun 06 1985 00:00:00 GMT+0800");
    System.out.println(formart.format(date));
      

  8.   

    public class Test1 {
    public static void main(String[] args) {

    String str = "Thu Jun 06 1985 00:00:00 GMT+0800 (中国标准时间)";
    System.out.println(getFormat(str));
    }
    public static String getFormat(String str){

    str = str.substring(0, str.indexOf('('));
    str = str.replace("GMT+08", "GMT+08:");

    try {
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy hh:mm:ss z", Locale.US);
    Date date = sdf.parse(str);
    SimpleDateFormat outSdf = new SimpleDateFormat("yyyy-MM-dd");
    return outSdf.format(date);
    } catch (ParseException e) {

    e.printStackTrace();

    }
    return null;
    }
    }
      

  9.   

    String str="Thu Jun 06 1985 00:00:00 GMT+0800 (中国标准时间)";
    SimpleDateFormat sdf=new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss' GMT'Z' (中国标准时间)'",Locale.ENGLISH);
    Date date=sdf.parse(str);
    SimpleDateFormat sdf_=new SimpleDateFormat("yyyy-MM-dd");
    String str_=sdf_.format(date);
    System.out.println(str_);