分享

EEE MMM dd yyyy HH:mm:ss' GMT'Z' (中国标准时间)格式转换

 魏正钦的图书馆 2015-07-21

得到的时间是“Thu Jun 06 1985 00:00:00 GMT+0800 (中国标准时间)” 这样的字符串

        怎么改成yyyy-MM-dd的格式啊? 
------Solutions------
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

format.format(字符串); 
------Solutions------
如果是字符串,你就要自己写一个程序。

拆分这个字符串,然后构造一个Calendar.

然后用SimpleDateFormat

明白吗? 
------Solutions------

引用 1 楼 w8320273 的回复:
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

format.format(字符串);


+1 
------Solutions------
“Thu Jun 06 1985 00:00:00 GMT+0800 (中国标准时间)”已经是字符串了,很难了,除非自己解析。
正确的做法应该是拿到时间对象,再用SimpleDateFormat 
------Solutions------
该回复于2012-02-22 11:42:53被版主删除 
------Solutions------
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

format.format("这是是日期");
出来的就是你想要的格式了。

------Solutions------
new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss' GMT'Z' (中国标准时间)'",Locale.ENGLISH); 
------Solutions------
引用 7 楼 antiwise 的回复:
new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss' GMT'Z' (中国标准时间)'",Locale.ENGLISH);


你看人家的需求了吗?

别误导人好吗? 
------Solutions------
该回复于2012-02-22 13:02:30被版主删除 
------Solutions------
csdn整天大姨妈 真2 
------Solutions------
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 
------Solutions------
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));

------Solutions------


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;
}
}


------Solutions------
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_);

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多