Mega Code Archive

 
Categories / VB.Net / Date Time
 

DateTime ToString converts DateTime to string using the specified format

Imports System.Globalization Imports System.Threading Module Example    Public Sub Main()       Dim date1 As Date = #7/21/2010#       Dim dft As CultureInfo       Dim heIL As New CultureInfo("he-IL")       heIL.DateTimeFormat.Calendar = New HebrewCalendar()       dft = Thread.CurrentThread.CurrentCulture       Thread.CurrentThread.CurrentCulture = heIL       Try          Console.WriteLine(date1.ToString("G"))       Catch e As ArgumentOutOfRangeException          Console.WriteLine("{0} is earlier than {1} or later than {2}", _                            date1.ToString("d", CultureInfo.InvariantCulture), _                            heIL.DateTimeFormat.Calendar.MinSupportedDateTime.ToString("d", CultureInfo.InvariantCulture), _                             heIL.DateTimeFormat.Calendar.MaxSupportedDateTime.ToString("d", CultureInfo.InvariantCulture))        End Try       Thread.CurrentThread.CurrentCulture = dft    End Sub End Module