VB.NET WORLD CLOCK Need help calculating TimeZones

I am trying to make a World Clock using VB.NET but I can't seem to use the timezone api to get the time differences for each country.

Can someone give me a suggestion as to how to access the time zone info that is already in the OS, I have started to build a whole new function to calculate the timezones but it is pretty boring and time consuming so it would be a great help if I could just grab the info from the api.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shane Russell2nd Line Desktop SupportCommented:
That was the only useful thing I found :


Just needs converted to dot net obviously.
M-PowerAuthor Commented:
Hi Gecko,

Sorry that does not really help me, I really need to know how to grab the info using VB.NET, that programe seems to be a tool for editing the time zone info.

Thanks, if you have a solution in VB.NET please advise, I am not interested in links to another app though, just info on how to do it if it is possible in VB.NET.
Hello, M-Power.

Unfortunately, there is no possible way to find out the time zone for each country in the world via WinAPI.
The closest possible thing to your goal is to use 'GetTimeZoneInformation' function to determine the time zone which was set for this particular machine by a user installing the Windows (or modifying time zone information).

You have to manually parse a list of countries (cities) and their respective time zones to achieve your goal. There is no such info in operating system.
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Registry key:
HKLM\Software\Microsoft\Windows NT\CurrentVersion\TimeZones

contains one sub-key for each time zone MS deals with
You can add and subtract time and dates with the time and date functions.

Why not just have a combo box, and when they select a certain country it just subtracts time from the current time. You would also need to compensate for the date too. Example.

It's 12:00 AM here, on 12/23/2008

In Hawaii it's what...erm.. 8PM? Something like that.

8 Pm 12/22/2005
The DateTime object has the following methods

ToUniversalTime  (converts the time to GMT)
ToLocalTime (convert GMT to the localtime)

obtained from

Then if you really want, can pull up some timezone info, make a database with the proper GMT offset, then you can take the system local time and apply an offset to hour to find the country desired.

As far as an automatic way of doing that, I'm not sure since Timezones are really weird  especially when they use daylight savings.

Ralf KlattEmployee in Civil ServiceCommented:

I'm working a lot with timezones and culture info and all I can say is that I always have to use help tables to create the appropriate timezone! Unfortunately, Win32 APIs do not offer a solution to enumerate information relative to any other time zone than the one currently selected by the user. GetLocalTime and GetSystemTime will allow you to retrieve the current local and the UTC times, respectively. To convert the local time to UTC, you can use the LocalFileTimeToFileTime API. These are but two of the many Win32 APIs dealing with time.

To retrieve the correct date and time formatting you'll be able to combine any "GMT Help Table" with the appropriate culture info ... a simple application to retrieve all .NET supported culture info is this:


Imports System
Imports System.Globalization

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    Private components As System.ComponentModel.IContainer
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Button1.Location = New System.Drawing.Point(88, 32)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Button1"
        Me.TextBox1.Location = New System.Drawing.Point(216, 16)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(680, 448)
        Me.TextBox1.TabIndex = 2
        Me.TextBox1.Text = ""
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(928, 565)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ci As CultureInfo
        For Each ci In CultureInfo.GetCultures(CultureTypes.AllCultures)
            TextBox1.Text = TextBox1.Text + ci.Name + vbTab + ci.TwoLetterISOLanguageName + vbTab + ci.ThreeLetterISOLanguageName + vbTab + ci.DisplayName + vbCrLf
        Next ci
    End Sub
End Class


As a basis for a "GMT Help Table" might serve you this:

Country      Start GMT      End GMT
Albania      GMT+01:00      
Algeria      GMT      
Andorra      GMT+01:00      
Angola      GMT+01:00      
Anguilla      GMT-04:00      
Antigua and Barbuda      GMT-04:00      
Argentina      GMT-03:00      
Armenia      GMT+04:00      
Aruba      GMT-04:00      
Ascension Island      GMT      
Australia      GMT+10:00      GMT+07:00
Austria      GMT+01:00      
Azerbaijan      GMT+04:00      
Bahamas      GMT-05:00      
Bahrain      GMT+03:00      
Bangladesh      GMT+06:00      
Barbados      GMT-04:00      
Belarus      GMT+03:00      
Belgium      GMT+01:00      
Belize      GMT-06:00      
Benin      GMT+01:00      
Bermuda      GMT-04:00      
Bhutan      GMT+05:30      
Bolivia      GMT-04:00      
Bosnia      GMT+01:00      
Botswana      GMT+02:00      
Brazil      GMT-03:00      GMT-05:00
Brunei      GMT+08:00      
Bulgaria      GMT+02:00      
Burkina Faso      GMT      
Burundi      GMT+02:00      
Cambodia      GMT+07:00      
Cameroon      GMT+01:00      
Canada      GMT-04:00      GMT-08:00
Cape Verde Islands      GMT-01:00      
Cayman Islands      GMT-05:00      
Central Africa Republic      GMT+01:00      
Chad      GMT+01:00      
Chile      GMT-04:00      
China      GMT+08:00      
Columbia      GMT-05:00      
Comoros Island      GMT+03:00      
Congo      GMT+01:00      
Cook Islands      GMT-10:00      
Costa Rica      GMT-06:00      
Croatia      GMT+01:00      
Cuba      GMT-03:00      
Cyprus      GMT+02:00      
Czech Republic      GMT+01:00      
Democratic Republic of Congo (Zaire)      GMT+02:00      GMT+01:00
Denmark      GMT+01:00      
Diego Garcia      GMT+05:00      
Djibouti      GMT+03:00      
Dominica Islands      GMT-04:00      
Dominican Republic      GMT-04:00      
Ecuador      GMT-05:00      
Egypt      GMT+02:00      
El Salvador      GMT-06:00      
Equatorial Guinea      GMT+01:00      
Eritrea      GMT+03:00      
Estonia      GMT+03:00      
Ethiopia      GMT+03:00      
Faeroe Islands      GMT      
Falkland Islands      GMT-04:00      
Fiji Islands      GMT+12:00      
Finland      GMT+02:00      
France      GMT+01:00      
French Guiana¬†      GMT-04:00      
French Polynesia      GMT-10:00      
Gabon      GMT+01:00      
Georgia      GMT+04:00      
Germany      GMT+01:00      
Ghana      GMT      
Gibraltar      GMT+01:00      
Greece      GMT+02:00      
Greenland      GMT-03:00      
Grenada      GMT-04:00      
Guadeloupe      GMT-04:00      
Guam      GMT+10:00      
Guatemala      GMT-06:00      
Guinea Bissau      GMT-01:00      
Guinea Republic      GMT      
Guyana      GMT-03:00      
Haiti      GMT-05:00      
Honduras      GMT-06:00      
Hong Kong      GMT+08:00      
Hungary      GMT+01:00      
Iceland      GMT      
India      GMT+05:30      
Indonesia      GMT+09:00      GMT+07:00
Iran      GMT+03:30      
Iraq      GMT+03:00      
Ireland      GMT      
Israel      GMT+02:00      
Italy      GMT+01:00      
Ivory Coast      GMT      
Jamaica      GMT-05:00      
Japan      GMT+09:00      
Jordan      GMT+02:00      
Kazakhstan      GMT+06:00      
Kenya      GMT+03:00      
Kiribati      GMT+12:00      
Korea, North      GMT+09:00      
Korea, South      GMT+09:00      
Kuwait      GMT+03:00      
Kyrgyzstan      GMT+06:00      
Laos      GMT+07:00      
latvia      GMT+03:00      
Lebanon      GMT+02:00      
Lesotho      GMT+02:00      
Liberia      GMT      
Libya      GMT+02:00      
Liechtenstein      GMT+01:00      
Lithuania      GMT+02:00      
Luxembourg      GMT+01:00      
Macau      GMT+08:00      
Macedonia (Fyrom)      GMT+01:00      
Madagascar      GMT+03:00      
Malawi      GMT+02:00      
Malaysia      GMT+08:00      
Maldives Republic      GMT+05:00      
Mali      GMT      
Malta      GMT+01:00      
Mariana Islands      GMT+10:00      
Marshall Islands      GMT+10:00      
Martinique      GMT-04:00      
Mauritius      GMT+04:00      
Mayotte Islands      GMT+03:00      
Mexico      GMT-06:00      GMT-08:00
Micronesia      GMT+10:00      
Moldova      GMT+03:00      
Monaco      GMT+01:00      
Mongolia      GMT+08:00      
Montserrat      GMT-04:00      
Morocco      GMT      
Mozambique      GMT+02:00      
Myanmar (Burma)      GMT+06:30      
Namibia      GMT+02:00      
Nauru      GMT+12:00      
Nepal      GMT+05:30      
Netherlands      GMT+01:00      
Netherlands Antilles      GMT-04:00      
New Caledonia      GMT+11:00      
New Zealand      GMT+12:00      
Nicaragua      GMT-06:00      
Niger      GMT+01:00      
Nigeria      GMT+01:00      
Niue Island      GMT-11:00      
Norfolk Island      GMT+11:30      
Norway      GMT+01:00      
Oman      GMT+04:00      
Pakistan      GMT+05:00      
Palau      GMT+09:00      
Palestine      GMT+02:00      
Panama      GMT-05:00      
Papua New Guinea      GMT+10:00      
Paraguay      GMT-04:00      
Peru      GMT-05:00      
Philippines      GMT+08:00      
Poland      GMT+01:00      
Portugal      GMT+01:00      
Puerto Rico      GMT-04:00      
Qatar      GMT+03:00      
Reunion Island      GMT+04:00      
Romania      GMT+02:00      
Russia      GMT+03:00      
Rwanda      GMT+02:00      
Samoa (American)      GMT-11:00      
Samoa (Western)      GMT-11:00      
San Marino      GMT+01:00      
Sao Tome & Principe      GMT      
Saudi Arabia      GMT+03:00      
Senegal      GMT      
Serbia      GMT+01:00      
Seychelles      GMT+04:00      
Sierra Leone      GMT      
Singapore      GMT+08:00      
Slovak Republic      GMT+01:00      
Slovenia      GMT+01:00      
Solomon Islands      GMT+11:00      
Somalia      GMT+03:00      
South Africa      GMT+02:00      
Spain      GMT+01:00      
Sri Lanka      GMT+05:30      
St Helena      GMT      
St Kitts & Nevia      GMT-04:00      
St Lucia      GMT-04:00      
Sudan      GMT+02:00      
Surinam      GMT-03:30      
Swaziland      GMT+02:00      
Sweden      GMT+01:00      
Switzerland      GMT+01:00      
Syria      GMT+02:00      
Taiwan      GMT+08:00      
Tajikistan      GMT+06:00      
Tanzania      GMT+03:00      
Thailand      GMT+07:00      
The Gambia      GMT      
Togo      GMT      
Tonga      GMT+13:00      
Trinidad & Tobago      GMT-04:00      
Tunisia      GMT+01:00      
Turkey      GMT+02:00      
Turkmenistan      GMT+05:00      
Turks & Caicos Islands      GMT-05:00      
Tuvalu      GMT+12:00      
Uganda      GMT+03:00      
Ukraine      GMT+03:00      
United Arab Emirates      GMT+04:00      
United Kingdom      GMT      
Uruguay      GMT-03:00      
USA      GMT-05:00      GMT-11:00
Uzbekistan      GMT+06:00      
Vanuatu      GMT+11:00      
Venezuela      GMT-04:00      
Vietnam      GMT+07:00      
Wallis & Futuna Islands      GMT+12:00      
Yemen Arab Republic      GMT+03:00      
Zambia      GMT+02:00      
Zimbabwe      GMT+02:00      

A "ready-to-use" working solution can surely not be found at Experts Exchange and so I hope that all suggestions to your question give you a good start for developing your World Time Application!

Best regards,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
M-PowerAuthor Commented:
Thank you to everyone for your help = ]
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.