Twitter Kitで取得できるTwitterクラスのcreatedAt
は、型がStringなのでDateとして扱うためにはparseする必要があります。
まぁ普通にSimpleDateFormat
を使ってparseするだけでいいんですが、ちょっとハマったのでメモを残します。
private static final String DATE_FORMAT_TWITTER = "EEE MMM dd HH:mm:ss ZZZZZ yyyy";
public static Date convertToDate(String twitterDate) {
// 第2引数のLocaleをセットしないとエラーになるので注意。
SimpleDateFormat sf = new SimpleDateFormat(DATE_FORMAT_TWITTER, Locale.ENGLISH);
try {
return sf.parse(twitterDate);
} catch (ParseException e) {
Log.e(TAG, e.getMessage());
return null;
}
}