Allow a leading space in the date string
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic
Public Class SamplesDTFI
Public Shared Sub Main()
Dim enUS As New CultureInfo("en-US")
Dim dateString As String
Dim dateValue As Date
dateString = " 5/01/2009 09:00"
If Date.TryParseExact(dateString, "MM/dd/yyyy hh:mm", enUS, _
DateTimeStyles.None, dateValue) Then
Console.WriteLine("Converted '{0}' to {1} ({2}).", dateString, dateValue, _
dateValue.Kind)
Else
Console.WriteLine("'{0}' is not in an acceptable format.", dateString)
End If
End Sub
End Class
Related examples in the same category