我想将时间从 RSS 提要转换为当地时间。这是它在 RSS 提要中的外观:
<pubDate>Sat, 16 Dec 2017 22:13:00 +0000</pubDate>
我想要做的是从那里获取 22:13 并将其转换为当地时间。这是代码:
if (current.getNodeName().equalsIgnoreCase("pubDate")) {
SimpleDateFormat inputFormat = new SimpleDateFormat("dd MMM yyyy", Locale.US);
Calendar cal = Calendar.getInstance();
cal.setTime(inputFormat.parse(currentTextContent.substring(5, 16)));
SimpleDateFormat outputFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.US); // 01-12
outputFormat.setTimeZone(TimeZone.getDefault());
String postTime = outputFormat.format(currentTextContent.substring(17, 22));
rssFeedModelItem.setPubDate(outputFormat.format(cal.getTime()));
System.out.println("Time"+" "+postTime);
rssFeedModelItem.setPubTime(postTime);
}
使用此代码应用程序不会出现互联网连接错误,这很奇怪。删除后:
String postTime = outputFormat.format(currentTextContent.substring(17, 22));
和改变
rssFeedModelItem.setPubTime(postTime);
进入这个:
rssFeedModelItem.setPubTime(currentTextContent.substring(17, 22));
该应用程序正在运行,但显示 RSS 时间。我也试过这个解决方案,但没有用。任何帮助表示赞赏。谢谢!
您可以尝试使用此模式解析整个日期
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句