RSS2.0 の pubDate フォーマットの日付時刻を SimpleDateFormat で解析する。

RSS2.0 の pubDate はこんな感じ。
<pubDate>Tue, 22 Sep 2009 19:24:08 +0900</pubDate>
曜日と月は US ロケールの文字列。
"+0900" は RFC820フォーマットのタイムゾーン解析文字 Z で解析する。


import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateFormatSample {
public static void main(String[] args) {
try {
String s = "Thu, 06 Aug 2009 08:21:24 +0900";
DateFormat input = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
Date d = input.parse(s);

DateFormat output = new SimpleDateFormat("yyyy/MM/dd (E) HH:mm:ss z");
System.out.println(output.format(d));
} catch (ParseException e) {
e.printStackTrace();
}
}
}

実行結果:
2009/08/06 (木) 08:21:24 +0900