bruchowski
bruchowski

Reputation: 5331

VB.net Time Zone Issues

I have a legacy application that uses the windows time zone information for calculating dates. For example, 35 = East Coast, 20 = central, 15=mountain. Here is the current function. It takes a date with a timezone and converts it to the timezone passed in. This works just fine on xp, but it crashes on Windows 7. I am guessing it has to do with the win32 portion of it or Windows 7 handles time zones differently.

I would prefer not to change the format of the time zone as that could cause some issues. The code is vb.net and I did not write it.

Public Shared Function ConvertTime(ByVal time As Date, ByVal timeZone As Integer) As Date
        Dim UtcNow As Date = time.ToUniversalTime

        Dim selectedTimeZone As TimeZones.Win32.Win32TimeZone = TimeZones.Win32.TimeZones.GetTimeZone(timeZone)

        Return selectedTimeZone.ToLocalTime(UtcNow)
    End Function

Anyone have this issue before?

Upvotes: 1

Views: 1578

Answers (2)

Dayan
Dayan

Reputation: 8031

Dim selectedTimeZone As TimeZones.Win32.Win32TimeZone =
TimeZones.Win32.TimeZones.GetTimeZone(timeZone)

In VB.NET you should be using the following class to replace Win32TimeZone

MSDN TimeZone Class (System)

Refer to the link i provided above to see the correct way of using the TimeZone Class in VB.NET.

It appears to not wont work due to TimZones.Win32.Win32TimeZone not being a valid class of .NET

Upvotes: 2

Sam Axe
Sam Axe

Reputation: 33738

That Timezones library is not a in the .NET BCL. Contact the author of your Timezones library for help.

Upvotes: 1

Related Questions