Posted on 2005-04-14
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
    LVL 7

    Accepted Solution

    I managed to find a service that connects an area code with a list of cities, from which you can obtain the time zone: 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 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

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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now