Parse date and time with custom specifier
Imports System.Globalization
Module MainClass
Public Sub Main()
Dim dateString, format As String
Dim result As Date
Dim provider As CultureInfo = CultureInfo.InvariantCulture
dateString = "Sun 15 Jun 2010 8:30 AM -06:00"
format = "ddd dd MMM yyyy h:mm tt zzz"
Try
result = Date.ParseExact(dateString, format, provider)
Console.WriteLine("{0} converts to {1}.", dateString, result.ToString())
Catch e As FormatException
Console.WriteLine("{0} is not in the correct format.", dateString)
End Try
End Sub
End Module
Related examples in the same category