1
運行這個程序:爲什麼SimpleDateFormat無法解析日期字符串中的weekday?
import java.text.*;
import java.util.*;
public class xx {
public static void main(String[] args) throws Exception {
final SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
format.setLenient(false);
format.parse("Tue, 16 Jan 2010 04:41:09 -0000");
}
}
給出了這樣的結果(java version "1.7.0_17"
):
Exception in thread "main" java.text.ParseException: Unparseable date: "Tue, 16 Jan 2010 04:41:09 -0000"
at java.text.DateFormat.parse(DateFormat.java:357)
at xx.main(xx.java:7)
看來,當設置爲非寬鬆模式下,Tue,
前綴是什麼無法解析。
問題是,爲什麼EEE,
未能匹配日期字符串的Tue,
前綴?
D'oh!謝謝。那麼簡單:) – Archie
請告訴我你不知道你的頭頂? (Stolen from [here](http://stackoverflow.com/a/6841479/1240557);)) – kryger