Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Parse All DateTime Format

$
0
0
 

Hi
I 'm still with my difficulties as beginner  in C # .

I am currently builfing a reader Rss Feed .
When the user enters RSS URL, the RSS data are saved in a database . (DATE , HEADLINES , DESCRIPTION , LINK , SOURE RSS )

I have no problem to do that .. Everything is displayed correctly.
Since I have more 100 or 200 feeds , I had the idea to classify them according to the recent publication date .
 - When I recovered the value that is in the <pubDate> tags in the XML file , I try to convert it into a standard format and then to the TimeStamp before saving . and classification works well too.
Here is the code that works very well so far

   DateTime sdateValue = new DateTime();

                        string dateString = ladate[x - 1].InnerText;
                        // string dateoutput;
                        if (DateTime.TryParse(dateString, out sdateValue))
                        {

 var timestamp = ToUnixTimestamp(sdateValue);
                        }
                        else
                        {
                             MessageBox.Show("  Unable to parse '{0}'.", dateString);
                        }

The witness, this is what I thought I came across a few RSS that have  the following formats:
Wed, 26 Feb 2014 05:27:04 EST
2/27/2014 8:40:16 PM GMT
my code is unable to convert these dates.
I want a function that can convert all formats dates possible 
I am doing research I came across some code like this but it does work .

                        DateTime sdateValue = new DateTime();
                         CultureInfo culture = CultureInfo.CreateSpecificCulture("it-IT");
                         DateTimeFormatInfo myDtfi = new DateTimeFormatInfo();

                        
                        String[] myPatternsArray = myDtfi.GetAllDateTimePatterns();


                        string dateString = ladate[x - 1].InnerText;
                        
                        if (DateTime.TryParseExact(dateString, myPatternsArray, culture, DateTimeStyles.None, out sdateValue))
                        {
                        var timestamp = ToUnixTimestamp(sdateValue);

                        }
                        else
                        {
                          //  MessageBox.Show("  Unable to parse '{0}'.", dateString);
                        }

I hope that you can help me to solve it .

- Finally I would ask the same opportunity if there is also a function that would allow you to encode and display other alphabets in my database (eg JAPANESE , Chinese, RUSSIAN ...) 

Thank you in advance 


AS


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>