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 983731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:54:19+00:00 2026-05-16T04:54:19+00:00

I am creating a web application that will display the dates of various events

  • 0

I am creating a web application that will display the dates of various events that happened within the application (like a document being produced, for instance). Of course, the date displayed needs to be considerate of where the user is located (not just blindly output the stored date, since that would be the server local time).

I’ve made a sample application that lists all the time zones, lets you choose one and then outputs some stored UTC dates in your selected time zone, adding an hour when the time zone is observing DST.

My question is: is this an optimal approach and/or have I missed something where by this approach won’t work in all cases?

static void Main(string[] args)
{
 List<DateTime> events = new List<DateTime>();

 events.Add(DateTime.UtcNow);
 events.Add(DateTime.UtcNow.AddDays(1));
 events.Add(DateTime.UtcNow.AddDays(7));

    var timeZones = TimeZoneInfo.GetSystemTimeZones();

 for (var i = 0; i < timeZones.Count; i++)
 {
  Console.WriteLine(i + " : " + timeZones[i].DisplayName);
 }

 var currentZone = timeZones[Convert.ToInt32(Console.ReadLine())];

 Console.WriteLine("UTC Event: {0}", events[0]);
 Console.WriteLine("Local Event: {0}", correct(events[0], currentZone));

 Console.ReadKey();
}

static DateTime correct(DateTime date, TimeZoneInfo timeZone)
{
 var correctedDate = date.AddHours(timeZone.BaseUtcOffset.TotalHours);

 if (timeZone.IsDaylightSavingTime(date))
 {
  return correctedDate.AddHours(1);
 }

 return correctedDate;
}

I’m getting the results I expect from the output, I’m just concerned that the complex issue of time zones can’t be this simple to solve.

  • 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-16T04:54:19+00:00Added an answer on May 16, 2026 at 4:54 am

    It’s much simpler than that 🙂

    Use TimeZoneInfo.ConvertTimeFromUtc – you don’t need to mess around with offsets yourself 🙂 (In particular, your current code assumes a DST difference of exactly one hour, which isn’t always correct.)

    You may want to use DateTimeOffset to avoid thinking that something’s in UTC when it’s not though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We’re creating a web application that will display contour areas as bitmaps in a
I am interested in creating a simple web application that will take in user
When creating a web application that some how displays the display of a unique
I'm creating a web application that will use a lot of ajax calls. The
I am currently creating a web application that will be deployed in an intranet
I'm creating a web application that will involve habitual file uploading and retrieval (PDFs,
I'm creating a web application that will use multiple types of users (e.g. Admin,
I'm looking into creating an Web or iPad application that will use HTML5. After
I am Creating a web application that will get homework from schools website. I
I am creating an internal web based application that will not be the target

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.