SimpleDateFormat
解析在JUnit测试(Robolectric测试转轮)中起作用,但在设备上运行时失败。英国夏令时--BST不被SimpleDateFormat识别时区
@Test
public void testDateParse() throws ParseException {
String datetime = "Wed Sep 03 12:59:27 BST 2014";
new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH)
.parse(datetime);
}
当它无法在设备上的异常说:
java.text.ParseException: Unparseable date: "Wed Sep 03 12:59:27 BST 2014" (at offset 20)
偏移20是BST
的B
,所以它的时区相关。
事实上"GMT"
工作:String datetime = "Wed Sep 03 12:59:27 GMT 2014";