Imports System
Class Sample
Public Shared Sub Main()
Dim saveNow As DateTime = DateTime.Now
Dim saveUtcNow As DateTime = DateTime.UtcNow
Dim myDt As DateTime
DisplayNow("UtcNow:", saveUtcNow)
DisplayNow("Now:", saveNow)
myDt = DateTime.SpecifyKind(saveNow, DateTimeKind.Utc)
Display("Utc:", myDt)
myDt = DateTime.SpecifyKind(saveNow, DateTimeKind.Local)
Display("Local:", myDt)
myDt = DateTime.SpecifyKind(saveNow, DateTimeKind.Unspecified)
Display("Unspecified:", myDt)
End Sub 'Main
Public Shared datePatt As String = "M/d/yyyy hh:mm:ss tt"
Public Shared Sub Display(ByVal title As String, ByVal inputDt As DateTime)
Dim dispDt As DateTime = inputDt
Dim dtString As String
dtString = dispDt.ToString(datePatt)
Console.WriteLine("{0} {1}, Kind = {2}", title, dtString, dispDt.Kind)
dispDt = inputDt.ToLocalTime()
dtString = dispDt.ToString(datePatt)
Console.WriteLine(" ToLocalTime: {0}, Kind = {1}", dtString, dispDt.Kind)
dispDt = inputDt.ToUniversalTime()
dtString = dispDt.ToString(datePatt)
Console.WriteLine(" ToUniversalTime: {0}, Kind = {1}", dtString, dispDt.Kind)
End Sub 'Display
Public Shared Sub DisplayNow(ByVal title As String, ByVal inputDt As DateTime)
Dim dtString As String = inputDt.ToString(datePatt)
Console.WriteLine("{0} {1}, Kind = {2}", title, dtString, inputDt.Kind)
End Sub
End Class