英文字符串转为Date
String strDate = "Tue Mar 14 22:30:29 CST 2017";
String s1 = "Sun Sep 02 2012 08:00:00 GMT+08:00";
SimpleDateFormat sf = new SimpleDateFormat("EEE MMM dd yyyy hh:mm:ss z",Locale.ENGLISH);//注意模式匹配
SimpleDateFormat sf2 = new SimpleDateFormat("EEE MMM dd hh:mm:ss z yyyy",Locale.ENGLISH);//注意模式匹配
Date d = sf.parse(s1);
Date d2 = sf2.parse(strDate);
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf2.format(d));//再次转为字符串
System.out.println(sdf2.format(d2));//再次转为字符串
Date date = new Date();
System.out.println(date.toString());
输出结果:
2012-09-02 08:00:00
2017-03-14 22:30:29
Tue Mar 14 23:20:12 CST 2017