new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss' GMT'Z' (中国标准时间)'",Locale.ENGLISH);
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
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));
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){
正确的做法应该是拿到时间对象,再用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
Date date = new Date("Thu Jun 06 1985 00:00:00 GMT+0800");
System.out.println(formart.format(date));
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;
}
}
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_);