我的字符串看起来像:Sun, 27-Oct-2013 11:31:31 GMT
为了让它更简单一点,我这样做:
if (s.length() > 10)
s = s.substring(5, s.length() - 4);
在那之后
s = " 27-Oct-2013 11:31:31"
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
Date timestamp = null;
try {
timestamp = formatter.parse(s.trim());
} catch (ParseException e) {
e.printStackTrace();
}
它捕获异常java.text.ParseException: Unparseable date: "27-Oct-2013 11:31:31"