Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 313035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:04:15+00:00 2026-05-12T08:04:15+00:00

I have a scenario where I have a timezone offset (in minutes) and need

  • 0

I have a scenario where I have a timezone offset (in minutes) and need to determine the timezone for it. I know that all the data is not available (for example, there may be several timezones with an offset of -240 minutes) but a “best guess” is acceptable.

My first pass looked like this:

foreach (var info in TimeZoneInfo.GetSystemTimeZones())
{
    if (info.BaseUtcOffset.TotalMinutes == timezoneOffset)
    {
         // do something here if this is a valid timezone
    }
}

This sorta works, but I need to account for daylight savings which is throwing me off somewhat. I added this terrible hack:

foreach (var info in TimeZoneInfo.GetSystemTimeZones())
{
    var extra = info.IsDaylightSavingTime(DateTime.Now) ? 60 : 0;
    if (info.BaseUtcOffset.TotalMinutes + extra == timezoneOffset)
    {
         // do something here if this is a valid timezone
    }
}

This works “well enough” in that I can show the user the correct time for them when daylight savings is not in effect and am about 70% correct during DST. Still… this is some awful code to my eyeballs.

Is there a better way to do this? More elegance would be good, and more accuracy would be better still.

Update

Technically I have access to any information Javascript can get regarding the date. I have a page on which I’ve placed a hidden field called “offset”. I have a JQuery function that populates the offset field with the DateTime().getTimezoneOffset(). While I don’t see anything on the DateTime object that will help, perhaps this will open other avenues for ideas.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:04:16+00:00Added an answer on May 12, 2026 at 8:04 am

    Short answer: you can’t.

    Daylight saving time make it impossible. For example, there is no way to determine, solely from UTC offset, the difference between Arizona and California in the summer, or Arizona and New Mexico in the winter (since Arizona does not observe DST).

    There is also the issue of what time different countries observe DST. For example, in the US DST starts earlier and ends later than in Europe.

    A close guess is possible (i.e. +/- an hour), but if you are using it to display time to users you will inevitably display the wrong time to some of them.


    Update: From the comments, it looks like your primary goal is to display a timestamp in the user’s local timezone. If that is what you want to do, you should send the time as a UTC timestamp, and then just rewrite it on the user’s browser with Javascript. In the case that they don’t have Javascript enabled, they would still see a usable UTC timestamp. Here is a function I came up with in this question, which I used in this Greasemonkey script. You may want to tweak it to suit your needs.

    //@param timestamp An ISO-8601 timestamp in the form YYYY-MM-DDTHH:MM:SS±HH:MM
    //Note: Some other valid ISO-8601 timestamps are not accepted by this function
    function parseISO8601(timestamp)
    {
      var regex = new RegExp("^([\\d]{4})-([\\d]{2})-([\\d]{2})T([\\d]{2}):([\\d]{2}):([\\d]{2})([\\+\\-])([\\d]{2}):([\\d]{2})$");
      var matches = regex.exec(timestamp);
      if(matches != null)
      {
        var offset = parseInt(matches[8], 10) * 60 + parseInt(matches[9], 10);
        if(matches[7] == "-")
          offset = -offset;
    
        return new Date(
          Date.UTC(
            parseInt(matches[1], 10),
            parseInt(matches[2], 10) - 1,
            parseInt(matches[3], 10),
            parseInt(matches[4], 10),
            parseInt(matches[5], 10),
            parseInt(matches[6], 10)
          ) - offset*60*1000
        );
      }
      return null;
    }
    

    Here is a function I use on my blog to display a parsed timestamp in the user’s local timezone. Again, you can tweak it to the format you want.

    var weekDays = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
            "Thursday", "Friday", "Saturday");
    var months = new Array("January", "February", "March", "April", "May", "June",
            "July", "August", "September", "October", "November", "December");
    
    function toLocalTime(date)
    {
      var hour = date.getHours();
      var ampm = (hour < 12 ? "am" : "pm");
      hour = (hour + 11)%12 + 1;
    
      var minutes = date.getMinutes();
      if(minutes < 10)
        minutes = "0" + minutes;
    
      return weekDays[date.getDay()] + ", "
           + months[date.getMonth()] + " "
           + date.getDate()          + ", "
           + date.getFullYear()      + " at "
           + hour                    + ":"
           + minutes                 + " "
           + ampm;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my data processing scenario I have some source data paths that have YY
I have scenario where I need to host a web service (WCF) on Azure
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that
I have the scenario where the data from a single table must be in
I have a scenario where, the data (both x and y coordinates) comes dynamically.
I have this scenario in my local network: [picture] http://fekt.datagrid.sk/DATA/stackoverflow/scenario.PNG Windows 2012: Only IIS
we are using Struts2 in our code and I have scenario where I need
I have a scenario where data needs to be imported from a CSV file
I have a scenario and I really need your help. I have a Silverlight
I have scenario, in which I am getting images using Web Service and all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.