InfoStatus
InfoStatus

Reputation: 7113

Convert From Local Time to UTC (Given the local TimeZone)

I've dates in different time zones.

How to convert them to UTC giving the respective time zone.

Something like this:

Dim Dated as DateTime = TempDate.ConvertToUniversalTime(TimeZone)

Upvotes: 1

Views: 8317

Answers (2)

InfoStatus
InfoStatus

Reputation: 7113

Here's how to do it

Dim TimeZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time")
Dim Dated As DateTime = TimeZoneInfo.ConvertTimeToUtc(TempDate, TimeZone)


For the TimeZones IDs check:

TimeZone.GetSystemTimeZones

Upvotes: 3

Kevin Loney
Kevin Loney

Reputation: 7553

The DateTime object in .net provides the DateTime.ToUniversalTime method. Since you are using the VB Date type the DateTime.FromOADate and DateTime.ToOAdate will provide conversion between the Date and DateTime types (see Interop Considerations under Programming Tips here).

UPDATE: You might also want to check out Converting Times Between Time Zones.

Upvotes: 4

Related Questions