Converts String to a DateTimeOffset, use more than one format : DateTimeOffset « Date Time « VB.Net






Converts String to a DateTimeOffset, use more than one format

  

Imports System
Imports System.Xml

Module Module1
    Sub Main()
        Dim reader As XmlReader = XmlReader.Create("myData.xml")
        reader.ReadToFollowing("time")
        Dim time As String = reader.ReadElementContentAsString()

        Dim formats As String() = {"yyyy-MM-ddTHH:mm:sszzzzzzz", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-dd"}
        Try
            Dim transaction_time As DateTimeOffset = XmlConvert.ToDateTimeOffset(time, formats)
            Console.WriteLine(transaction_time)
        Catch e As Exception
            Console.WriteLine(e)
        End Try
    End Sub
End Module

   
    
  








Related examples in the same category

1.Converts String to a DateTimeOffset equivalent with format.
2.Converts the supplied DateTimeOffset to a String.
3.Converts the supplied DateTimeOffset to a String in the specified format.