別の SimpleDateFormat の質問を投稿したくないのですが、Google や他のスレッドで回答が見つかりません。私のコードは以下で、コメントは問題を示しています。
// The dateString format is "Thu Jul 19 00:04:11 +0000 2012". I confirmed that there
// is no preceding or trailing white space.
public static GregorianCalendar stringToDate(String dateString) {
GregorianCalendar calendar = new GregorianCalendar();
ParsePosition pos = new ParsePosition(0);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM d H:mm:ss Z yyyy");
Date date = simpleDateFormat.parse(dateString, pos);
// 'Unknown Source' error thrown by setTime() as date is ultimately null.
calendar.setTime(date);
return calendar;
}
dateString パラメータが正しく通過することを確認しました。位置オブジェクトは 0 から始まります。SimpleDateFormat をhttp://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormatに対して何度も確認しました。 .html . 私には正しいように見えますが、「d」と「H」のさまざまな順列をまだテストしています。私が考えることができる唯一のことは、私が見逃している、または私がベースから外れているというニュアンスがあるということです.
これはコンパイルされますが (javac 1.6.0_33)、実行されると (Java バージョン "1.6.0_33")、渡された最初の dateString 値でさえ処理されません。Windows 7 64 ビット、日本語版を実行しています。
どんな支援も大歓迎です。