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 8:30 AM"
If Date.TryParseExact(dateString, "g", 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
' Allow a leading space in the date string.
If Date.TryParseExact(dateString, "g", enUS,DateTimeStyles.AllowLeadingWhite, 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