Attempt to convert a string in improper ISO 8601 format
Imports System.Globalization
Module ParseDateExample
Public Sub Main()
Dim dateString As String
Dim culture As CultureInfo
Dim styles As DateTimeStyles
Dim result As DateTime
dateString = "03/01/2009T10:00:00-5:00"
Try
result = DateTime.Parse(dateString, culture, styles)
Console.WriteLine("{0} converted to {1} {2}.", _
dateString, result, result.Kind.ToString())
Catch e As FormatException
Console.WriteLine("Unable to convert {0} to a date and time.", dateString)
End Try
End Sub
End Module
Related examples in the same category