Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27186

timezone and time display

$
0
0
Not sure if this is the right section to post this, but I am using Visual Basic 2010 Express, with .Net (Pretty sure the language is Java by default for Application Forms)
- Im new to the forums... And I know the question is really basic and probably has a really simple answer, but nothing me or my friends tried have worked.
Anyway...

I built a program, that will simply let you select 2 regions (a from and a to), and it will do some behind-the-scenes stuff to get the current time (Hours, and minutes), the offset (that - or + # number thing), and the timezone (UTC,EST,etc)

The offset, and the timezone works (that, I just simply put in manually, seeing as I already know the timezone for that region, I dont need to program it)

The problem is:
The current time, it will only work fine on my computer, but thats only because its using my computers clock, how do I make it use either the users clock to get the right time for their area, or use a certain timezone's clock (like mine - Canada) so I can just subtract the right offset, to get the time for whatever region they select?

And:
Now
TimeOfDay
gives the current systems time (my computers time), so if I was to send the program to a friend on a different computer, then it would be programmed to that computers time

Any other alternate solutions that doesnt get my systems time would be great, thank you.

Here is my code I have right now (again, it fully works... Only on my computer though)
Code:

Private Sub convertTo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles convertTo.SelectedIndexChanged
        'Canadian - S.American
        If convertFrom.Text = "Canadian Timezone" Then
            If convertTo.SelectedItem = "S.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24 - 3).ToShortTimeString

                timezoneType.Text = "PST"
                offOnValue.Text = "-3"
            End If
        End If

        'Canadian - Zealand
        If convertFrom.SelectedItem = "Canadian Timezone" Then
            If convertTo.SelectedItem = "New Zealand Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24 + 16).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+16"
            End If
        End If

        'Canadian - N.American
        If convertFrom.SelectedItem = "Canadian Timezone" Then
            If convertTo.SelectedItem = "N.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24 - 1).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "-1"
            End If
        End If

        'Canadian - Canadian
        If convertFrom.SelectedItem = "Canadian Timezone" Then
            If convertTo.SelectedItem = "Canadian Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "0"
            End If
        End If


        'S.American - S.American
        If convertFrom.Text = "S.American Timezone" Then
            If convertTo.SelectedItem = "S.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24 - 3).ToShortTimeString

                timezoneType.Text = "PST"
                offOnValue.Text = "+0"
            End If
        End If

        'S.American - Zealand
        If convertFrom.SelectedItem = "S.American Timezone" Then
            If convertTo.SelectedItem = "New Zealand Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(16).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "-5"
            End If
        End If

        'S.American - N.American
        If convertFrom.SelectedItem = "S.American Timezone" Then
            If convertTo.SelectedItem = "N.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(23).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+2"
            End If
        End If

        'S.American - Canadian
        If convertFrom.SelectedItem = "S.American Timezone" Then
            If convertTo.SelectedItem = "Canadian Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+3"
            End If
        End If


        'N.American - S.American
        If convertFrom.Text = "N.American Timezone" Then
            If convertTo.SelectedItem = "S.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(21).ToShortTimeString

                timezoneType.Text = "PST"
                offOnValue.Text = "-2"
            End If
        End If

        'N.American - Zealand
        If convertFrom.SelectedItem = "N.American Timezone" Then
            If convertTo.SelectedItem = "New Zealand Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(4).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "-16"
            End If
        End If

        'N.American - N.American
        If convertFrom.SelectedItem = "N.American Timezone" Then
            If convertTo.SelectedItem = "N.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(23).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+0"
            End If
        End If

        'N.American - Canadian
        If convertFrom.SelectedItem = "N.American Timezone" Then
            If convertTo.SelectedItem = "Canadian Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+1"
            End If
        End If


        'New Zealand - S.American
        If convertFrom.Text = "New Zealand Timezone" Then
            If convertTo.SelectedItem = "S.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(33).ToShortTimeString

                timezoneType.Text = "PST"
                offOnValue.Text = "+5"
            End If
        End If

        'New Zealand - Zealand
        If convertFrom.SelectedItem = "New Zealand Timezone" Then
            If convertTo.SelectedItem = "New Zealand Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(40).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "0"
            End If
        End If

        'New Zealand - N.American
        If convertFrom.SelectedItem = "New Zealand Timezone" Then
            If convertTo.SelectedItem = "N.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(35).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+7"
            End If
        End If

        'New Zealand - Canadian
        If convertFrom.SelectedItem = "New Zealand Timezone" Then
            If convertTo.SelectedItem = "Canadian Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+8"
            End If
        End If
    End Sub

    Private Sub convertFrom_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles convertFrom.SelectedIndexChanged
        'Canadian - S.American
        If convertFrom.Text = "Canadian Timezone" Then
            If convertTo.SelectedItem = "S.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24 - 3).ToShortTimeString

                timezoneType.Text = "PST"
                offOnValue.Text = "-3"
            End If
        End If

        'Canadian - Zealand
        If convertFrom.SelectedItem = "Canadian Timezone" Then
            If convertTo.SelectedItem = "New Zealand Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24 + 16).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+16"
            End If
        End If

        'Canadian - N.American
        If convertFrom.SelectedItem = "Canadian Timezone" Then
            If convertTo.SelectedItem = "N.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24 - 1).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "-1"
            End If
        End If

        'Canadian - Canadian
        If convertFrom.SelectedItem = "Canadian Timezone" Then
            If convertTo.SelectedItem = "Canadian Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "0"
            End If
        End If


        'S.American - S.American
        If convertFrom.Text = "S.American Timezone" Then
            If convertTo.SelectedItem = "S.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24 - 3).ToShortTimeString

                timezoneType.Text = "PST"
                offOnValue.Text = "+0"
            End If
        End If

        'S.American - Zealand
        If convertFrom.SelectedItem = "S.American Timezone" Then
            If convertTo.SelectedItem = "New Zealand Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(16).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "-5"
            End If
        End If

        'S.American - N.American
        If convertFrom.SelectedItem = "S.American Timezone" Then
            If convertTo.SelectedItem = "N.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(23).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+2"
            End If
        End If

        'S.American - Canadian
        If convertFrom.SelectedItem = "S.American Timezone" Then
            If convertTo.SelectedItem = "Canadian Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+3"
            End If
        End If


        'N.American - S.American
        If convertFrom.Text = "N.American Timezone" Then
            If convertTo.SelectedItem = "S.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(21).ToShortTimeString

                timezoneType.Text = "PST"
                offOnValue.Text = "-2"
            End If
        End If

        'N.American - Zealand
        If convertFrom.SelectedItem = "N.American Timezone" Then
            If convertTo.SelectedItem = "New Zealand Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(4).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "-16"
            End If
        End If

        'N.American - N.American
        If convertFrom.SelectedItem = "N.American Timezone" Then
            If convertTo.SelectedItem = "N.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(23).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+0"
            End If
        End If

        'N.American - Canadian
        If convertFrom.SelectedItem = "N.American Timezone" Then
            If convertTo.SelectedItem = "Canadian Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+1"
            End If
        End If


        'New Zealand - S.American
        If convertFrom.Text = "New Zealand Timezone" Then
            If convertTo.SelectedItem = "S.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(33).ToShortTimeString

                timezoneType.Text = "PST"
                offOnValue.Text = "+5"
            End If
        End If

        'New Zealand - Zealand
        If convertFrom.SelectedItem = "New Zealand Timezone" Then
            If convertTo.SelectedItem = "New Zealand Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(40).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "0"
            End If
        End If

        'New Zealand - N.American
        If convertFrom.SelectedItem = "New Zealand Timezone" Then
            If convertTo.SelectedItem = "N.American Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(35).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+7"
            End If
        End If

        'New Zealand - Canadian
        If convertFrom.SelectedItem = "New Zealand Timezone" Then
            If convertTo.SelectedItem = "Canadian Timezone" Then
                newTimeZone.Text = TimeOfDay.AddHours(24).ToShortTimeString

                timezoneType.Text = "UTC"
                offOnValue.Text = "+8"
            End If
        End If
    End Sub


Viewing all articles
Browse latest Browse all 27186

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>