Converts the supplied String to a DateTimeOffset equivalent. : XML Convert « XML LINQ « C# / C Sharp






Converts the supplied String to a DateTimeOffset equivalent.

 

using System;
using System.Xml;

class Example
{
    static void Main()
    {
        XmlReader reader = XmlReader.Create("transactions.xml");
        reader.ReadToFollowing("time");
        string time = reader.ReadElementContentAsString();

        string[] formats = {"yyyy-MM-ddTHH:mm:sszzzzzzz", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-dd"};
        try
        {
            DateTimeOffset transaction_time = XmlConvert.ToDateTimeOffset(time, formats);
            Console.WriteLine(transaction_time);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
}

   
  








Related examples in the same category

1.Decodes a name. This method does the reverse of the EncodeName and EncodeLocalName methods.
2.Converts the DateTime to a String.
3.Converts the supplied DateTimeOffset to a String.
4.Converts the supplied DateTimeOffset to a String in the specified format.
5.Verifies that the name is a valid name according to the W3C Extended Markup Language recommendation.
6.Verify Xml Chars