Question : how do i get the timezone

How do i get all the time zones using vb.net  in a single combo box,

i have tried all these.....
 imports system.timezone

dim tz as string  = timezone.[many things here]

Please can i get to know how do i interact with the timezone class and the timezone registry to get all the time zones that the system has.....
Please help me at the earliest....

Answer : how do i get the timezone

kals,
The function GetTimeZones will return the TimeZone name and the TimeZone display (Which includes a little more information about the time zone) as a two dimensional array.  You should be able to use it to add the time zones to a combo box.

Let me know if it works for you...


''' Example function that uses GetTimeZones() '''
Sub Main()
    Dim timeZones As String(,)
    Dim i As Long
    timeZones = GetTimeZones()

    For i = 0 To UBound(timeZones) - 1
      Console.WriteLine("{0} : {1}", timeZones(i, 0), timeZones(i, 1))
    Next
    Console.Read()
  End Sub

''' The Function I think you are looking for '''
  Public Function GetTimeZones() As String(,)
    Dim rTimeZones As RegistryKey
    Dim rTimeZone As RegistryKey
    Dim sTimeZones As String()
    Dim sTimeZonesKey As String
    Dim sTimeZoneKey As String
    Dim retVal As String(,)
    Dim i As Long

    'Check for WinNT/2K
    sTimeZonesKey = "Software\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"
    rTimeZones = Registry.LocalMachine.OpenSubKey(sTimeZonesKey, False)

    'Check for Win98/XP
    If (rTimeZones Is Nothing) Then
      sTimeZonesKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Time Zones"
      rTimeZones = Registry.LocalMachine.OpenSubKey(sTimeZonesKey, False)
    End If

    sTimeZones = rTimeZones.GetSubKeyNames()
    ReDim retVal(sTimeZones.Length, 2)
    For i = 0 To sTimeZones.Length - 1
      sTimeZoneKey = sTimeZonesKey & "\\" & sTimeZones(i)
      rTimeZone = Registry.LocalMachine.OpenSubKey(sTimeZoneKey)
      retVal(i, 0) = sTimeZones(i)
      retVal(i, 1) = rTimeZone.GetValue("Display")
    Next
    Return retVal
  End Function

Random Solutions  
 
programming4us programming4us