Convert.ToDateTime(String) converts string to date and time value. : Convert « Development « VB.Net






Convert.ToDateTime(String) converts string to date and time value.

  

Module ConversionToDateTime
   Public Sub Main()
      Dim dateString As String = Nothing
      dateString = "05/01/2010"
      ConvertToDateTime(dateString)
      dateString = "Tue Apr 28, 2010"
      ConvertToDateTime(dateString)
      dateString = "Wed Apr 28, 2010"
      ConvertToDateTime(dateString)
      dateString = "06 July 2010 7:32:47 AM"
      ConvertToDateTime(dateString)
      dateString = "17:32:47.003"
      ConvertToDateTime(dateString)
      dateString = "Sat, 10 May 2010 14:32:17 GMT"
      ConvertToDateTime(dateString)
   End Sub

   Private Sub ConvertToDateTime(value As String)
      Dim convertedDate As Date
      Try
         convertedDate = Convert.ToDateTime(value)
         Console.WriteLine("'{0}' converts to {1}.", value, convertedDate)
      Catch e As FormatException
         Console.WriteLine("'{0}' is not in the proper format.", value)
      End Try
   End Sub
End Module

   
    
  








Related examples in the same category

1.Convert.ChangeType
2.Convert numeric string to SByte without a format provider
3.Convert numeric string to SByte with a format provider.
4.Converting strings to numbers in base
5.Convert.ToBase64CharArray converts 8-bit unsigned integer array to Unicode character array
6.Convert the Char array back to a Byte array
7.Convert.ToBase64String converts 8-bit unsigned integers to string encoded with base-64 digits.
8.Convert string by different base
9.Convert.ToDateTime (Object) converts object to a DateTime object.
10.Convert.ToDateTime Method (Object, IFormatProvider) converts object to DateTime using culture-specific format
11.Convert.ToDateTime(String, IFormatProvider) converts string to date and time, using culture-specific format
12.Convert single value to decimal
13.Convert hex string to Int16
14.Convert hex string to int64
15.Convert Long to Integer
16.Convert double to Integer
17.Convert BigInteger to Integer
18.Convert decimal to Integer