0

I'm parsing multiple RSS feed and I need to get 'pubdate' from item, but for some of these dates I get format in different language, so my code fails if format language is not english.

with these kind of that of course it works:enter code here

Sun, 28 May 2017 14:44:06

with these dates doesn't work:

Dom, 28 Mag 2017 12:16:48

and here my piece of code:

String parseFormat = "ddd, dd MMM yyyy HH:mm:ss";
DateTime date = DateTime.ParseExact(pubDate, parseFormat, CultureInfo.InvariantCulture);
pubDate = date.ToString("dd/MMM HH:mm:ss");

how can I manage multiple language in one code

Noomak
  • 371
  • 5
  • 19

2 Answers2

0

I've found that with this code you can get the date in any culture and then use it with your DateTime object:

DateTime date = Convert.ToDateTime(pubDate);                
pubDate = date.ToString();

the format is

dd/MMM/yyyy HH:mm:ss
Noomak
  • 371
  • 5
  • 19
0

The Solution i can think of is with every feed you need to set the date format and Culture, you can use any configuration source for it.
then use the code snippet below

String parseFormat = "ConfiguredFormatForthisRSSFeed"; 
DateTime date = DateTime.ParseExact(pubDate, parseFormat, configuredCultureforthisRSSFeed);
pubDate = date.ToString("dd/MMM HH:mm:ss");
Basant Sahu
  • 321
  • 2
  • 7