[Last Call] Learn how to a build a cloud-first strategyRegister Now



Posted on 2005-04-14
Medium Priority
Last Modified: 2010-04-16
Is there a component out there for getting the local time for a given area code.......

Thanks in advance

Question by:CDFA_Inc2

Accepted Solution

Ceiled earned 750 total points
ID: 13786798
I managed to find a service that connects an area code with a list of cities, from which you can obtain the time zone: http://www.xmethods.net/ve2/ViewListing.po?key=uuid:6F25C11C-7087-73ED-20B8-71AF6DC69E42. It returns an XmlNode (from which you can load a DataSet) containing information about major cities in the specified area code, including a code representing their time zone: "P", "M", "C" or "E" for Pacific, Mountain, Central or Eastern. It's unfortunate that it uses this instead of returning the UTC offset or something, but you can easily hard-code them if you only need this to work for US area codes. Also note that I'm not responsible for the service, and that you'll have to talk to the person who exposes it to find out how reliable it is, etc. I can't be held responsible if it suddenly disappears some time in the future. Anyway, here's the code I used to print out the local time in an area code after adding a web reference to the WSDL file the service exposes:

USZip z = new USZip();
string s;
while ((s = Console.ReadLine()) != null)
      XmlNode xn = z.GetInfoByAreaCode(s);
      DataSet ds = new DataSet();
      ds.ReadXml(new XmlNodeReader(xn));

      int hours = 0;

      switch (ds.Tables["Table"].Rows[0]["TIME_ZONE"] as string)
            case "P":
                  hours = -8;
            case "M":
                  hours = -7;
            case "C":
                  hours = -6;
            case "E":
                  hours = -5;
      if (!TimeZone.IsDaylightSavingTime(DateTime.UtcNow, TimeZone.CurrentTimeZone.GetDaylightChanges(DateTime.UtcNow.Year)))

Note that this code probably won't work if you run it too close to a daylight saving boundary, because .NET will only give you information about your current time zone. There's a library at http://www.michaelbrumm.com/simpletimezone.html that should be able to fix this issue, but I'll leave that as an exercise for the reader. Hope this helps, and let me know if you have any questions about the code.

Author Comment

ID: 13851790
Reliability may be a problem.  I may write one for people and put it up!

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

834 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