0

I want to convert time from RSS feed into local time. Here is how it looks in RSS feed:

<pubDate>Sat, 16 Dec 2017 22:13:00 +0000</pubDate>

What I want to do is getting that 22:13 from there and converting it into local time. Here is the code:

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);
                            }

With this code app is giving no Internet connection error which is strange. After removing this:

String postTime = outputFormat.format(currentTextContent.substring(17, 22));

And changing

rssFeedModelItem.setPubTime(postTime);

into this:

rssFeedModelItem.setPubTime(currentTextContent.substring(17, 22));

the app is working but showing RSS time. I also tried this solution but it's not worked. Any help is appreciated. Thanks!

Red Shaman
  • 139
  • 10

1 Answers1

1

You can try to parse the whole date with this pattern

new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z")
elmorabea
  • 3,243
  • 1
  • 14
  • 20
  • Yeah but I don't need whole date. I only need to convert the time to another timezone. It's not possible? – Red Shaman Dec 17 '17 at 16:00
  • After you have parsed the date, you can use another formatter to print whatever you want in whatever timezone you need – elmorabea Dec 17 '17 at 16:01