Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Getting UTC OFFSET OF a timezone

Posted on 2010-09-02
Medium Priority
Last Modified: 2012-05-10
I need a way on a clients pc to query what that pc believes is the UTC offset of any timezone so I can add or subtract it from the UTC of their timezone to get the offset in hours from the particular timezone

example: running code on a pc in eastern timezone i need to get the UTC
i want to pass in the timezone for Mountain and then add or subtract that value form the eastern timezone to get teh number of hours diffence
Dim tzTimeZone As TimeZone = System.TimeZone.CurrentTimeZone
        Dim tsUTCoffset As Integer = tzTimeZone.GetUtcOffset(Now()).Hours

Open in new window

Question by:hainansyndrome
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33591618
try this....
DateTime.Now will return the "current" time based on your time zone.

DateTime.ToUniversalTime will return GMT time.

You can subtract the two values to get the difference...

Dim now As DateTime = DateTime.Now
Dim nowGMT As DateTime = now.ToUniversalTime()
Dim diff As TimeSpan = now.Subtract(nowGMT)
Debug.WriteLine(diff, "diff")

Open in new window

LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33591692
You can also read this ...there is a good example ...

Author Comment

ID: 33591699
no i need to get the difference of 2 timezones

1 being the zone of the pc this code is running off of
and the other being a random zone
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33591794
you can use for any other pc this:
Dim OtherPcOffset As TimeSpan TimeZoneInfo.Local.GetUtcOffset(DateTimeOffset.Now)
REad this article ...
about Converting DateTimeOffset Values

Author Comment

ID: 33595825
ok hmmmmmmmm maybe this makes more sense

we are pulling data from a webservice to a PC
this pc could be in any timeszone, I have no trouble getting the timezone information for that timezone

the data from the webservice is a date time, so it gets offset to that timezone

SInce DST changed a while back i cant hard code Central TIme Zones offset
I need to get Central Time's offset per that PC to then add or substract from that Timeezones so I know how many hours i need to add or subtract from my date time

perviously we were just adding 12 hours to the datetime but i want it right
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33595961

Author Comment

ID: 33607890
i read it and the problem i come up with is that central time is not always GMT -6 it is sometimes -5
it all hangs on DST just need a function that can grab all the settings from the local machine
anything short of changing the timezone to get the settings
LVL 18

Accepted Solution

John (Yiannis) Toutountzoglou earned 1500 total points
ID: 33608027
You can use a combination of all above...
You can always detect when daylight saving is applied on a client using this:
Dim t As TimeZone = System.TimeZone.CurrentTimeZone
Dim dls as boolean = t.IsDaylightSavingTime(Now)

PS: pc clock will auto update daylightsaving if needed

Also take a look here

Author Closing Comment

ID: 33718866
took some digging around

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question