How to Calculate the Time Zone Difference in VB6

Written by ryan menezes
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Calculate the Time Zone Difference in VB6
Visual Basic can compare different time zones. (black magnifier on world map with time zones image by Anatoly Tiplyashin from

Visual Basic's "TimeZoneInfo" variable type sets specific time zones from around the world as variables. Additional commands perform operations on the TimeZoneInfo variable just as VBA commands do with other variables. Some commands find the current time in the time zone. Others convert these times into dates. Commands that compare dates then find the difference between two times, finding the hours that separate two time zones that you pick.

Skill level:


  1. 1

    Create a Visual Basic program from the following Microsoft code:

    Imports System.Collections.ObjectModel

    Imports System.Globalization

    Imports System.IO

    Module Example

    Public Sub Main()

    Const OUTPUTFILENAME As String = "C:\Temp\TimeZoneInfo.txt"

    Dim time Zones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()

    Dim sw As StreamWriter = New StreamWriter(OUTPUTFILENAME, False)

    For Each timeZone As TimeZoneInfo in time Zones

    Dim hasDST As Boolean = timeZone.SupportsDaylightSavingTime

    Dim offsetFromUtc As TimeSpan = timeZone.BaseUtcOffset

    Dim adjust Rules() As System.TimeZoneInfo.AdjustmentRule

    Dim offset String As String

    sw.WriteLine("ID: {0}", timeZone.Id)

    sw.WriteLine(" Display Name: {0, 40}", timeZone.DisplayName)

    sw.WriteLine(" Standard Name: {0, 39}", timeZone.StandardName)

    sw.Write(" Daylight Name: {0, 39}", timeZone.DaylightName)

    sw.Write(iif(hasDST, " Has ", " Does Not Have "))

    sw.WriteLine("Daylight Saving Time***")

    offset String = String.Format("{0} hours, {1} minutes", offsetFromUtc.Hours, offsetFromUtc.Minutes)

    sw.WriteLine(" Offset from UTC: {0, 40}", offset String)

    adjust Rules = timeZone.GetAdjustmentRules()

    sw.WriteLine(" Number of adjustment rules: {0, 26}", adjustRules.Length)

    If adjustRules.Length > 0 Then

    sw.WriteLine(" Adjustment Rules:")

    For Each rule As TimeZoneInfo.AdjustmentRule In adjust Rules

    Dim transTimeStart As TimeZoneInfo.TransitionTime = rule.DaylightTransitionStart

    Dim transTimeEnd As TimeZoneInfo.TransitionTime = rule.DaylightTransitionEnd

    sw.WriteLine(" From {0} to {1}", rule.DateStart, rule.DateEnd)

    sw.WriteLine(" Delta: {0}", rule.DaylightDelta)

    If Not transTimeStart.IsFixedDateRule

    sw.WriteLine(" Begins at {0:t} on {1} of week {2} of {3}", transTimeStart.TimeOfDay, _

    transTimeStart.DayOfWeek, _

    transTimeStart.Week, _


    sw.WriteLine(" Ends at {0:t} on {1} of week {2} of {3}", transTimeEnd.TimeOfDay, _

    transTimeEnd.DayOfWeek, _

    transTimeEnd.Week, _



    sw.WriteLine(" Begins at {0:t} on {1} {2}", transTimeStart.TimeOfDay, _

    transTimeStart.Day, _


    sw.WriteLine(" Ends at {0:t} on {1} {2}", transTimeEnd.TimeOfDay, _

    transTimeEnd.Day, _


    End If


    End If



  2. 2

    Run the program. It will list your registry's time zone IDs.

  3. 3

    Create a second Visual Basic program with the following code:

    Public Shared Sub() Main

    Dim first Zone As TimeZoneInfo

    first Zone = TimeZoneInfo.FindSystemTimeZoneByID("Eastern Standard Time")

    Dim second Zone As TimeZoneInfo

    second Zone = TimeZoneInfo.FindSystemTimeZoneByID("Central Standard Time")

    Dim difference As Long = DateDiff(DateInterval.Hour, firstZone.StandardTime, secondZone.StandardTime)


  4. 4

    Replace "Eastern Standard Time" with the first time zone you want to compare. Make sure you reproduce the precise ID from the list from Step 1.

  5. 5

    Replace "Central Standard Time" with the second time zone you want to compare. Again, reproduce the precise ID from the list from Step 1.

  6. 6

    Run the program.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.