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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:57:41+00:00 2026-06-14T00:57:41+00:00

I have some outdated code that attempts to account for the change in time

  • 0

I have some outdated code that attempts to account for the change in time caused by daylight savings that looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 31; i++)
            {
                DateTime dt = new DateTime(1960, 3, i, 0, 0, 0);
                Console.WriteLine(dt.ToUniversalTime());
            }

            Console.WriteLine();

            for (int i = 1; i <= 30; i++)
            {
                DateTime dt = new DateTime(1960, 4, i, 0, 0, 0);
                Console.WriteLine(dt.ToUniversalTime());
            }

            Console.ReadKey();
        }
    }
}

This code iterates through the days in March and April in 1960 and prints the datetime.
However, this does not correctly account for the time change in 1960, I believe because the date of the time change was different then. I attempted to fix this using the TimeZoneInfo class. I changed the code to the following:

class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 31; i++)
            {
                DateTime dt = new DateTime(1960, 3, i, 0, 0, 0);
                var tz = TimeZoneInfo.Local;
                var utcOffset = new DateTimeOffset(dt, TimeSpan.Zero);
                //use timeZoneInfo class to account for dlst offset
                Console.WriteLine(utcOffset.ToOffset(tz.GetUtcOffset(utcOffset)));
            }

            Console.WriteLine();

            for (int i = 1; i <= 30; i++)
            {
                DateTime dt = new DateTime(1960, 4, i, 0, 0, 0);
                var tz = TimeZoneInfo.Local;
                var utcOffset = new DateTimeOffset(dt, TimeSpan.Zero);
                //use timeZoneInfo class to account for dlst offset
                Console.WriteLine(utcOffset.ToOffset(tz.GetUtcOffset(utcOffset)));

            }

            Console.ReadKey();
        }
    }

Unfortunately, this is printing out:
enter image description here

which shows that daylight savings is changing on April 3rd at 4 p.m., while it should be switching over at April 24th at 2:00 a.m. What am I missing to correctly account for daylight savings?

EDIT:
My current time zone is eastern.

  • 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-06-14T00:57:42+00:00Added an answer on June 14, 2026 at 12:57 am

    It looks like the Windows time zone information doesn’t match what I’d have expected via TZDB. Here’s a program using Noda Time to show all the transitions between ~1960 and 1965 with both the BCL TimeZoneInfo (wrapped) and the TZDB 2012i data:

    using System;
    using NodaTime;
    
    class Test
    {
        static void Main()
        {
            var bcl = DateTimeZoneProviders.Bcl["Eastern Standard Time"];
            var tzdb = DateTimeZoneProviders.Tzdb["America/New_York"];
    
            ShowTransitions(bcl);
            ShowTransitions(tzdb);
        }
    
        static void ShowTransitions(DateTimeZone zone)
        {
            Console.WriteLine("Transitions for {0}", zone.Id);
            Instant start = Instant.FromUtc(1960, 1, 1, 0, 0);
            Instant end = Instant.FromUtc(1965, 1, 1, 0, 0);
            var interval = zone.GetZoneInterval(start);
            while (interval.Start < end)
            {
                Console.WriteLine(interval.Start);
                interval = zone.GetZoneInterval(interval.End);
            }
            Console.WriteLine();
        }
    }
    

    Output:

    Transitions for Eastern Standard Time
    1959-10-25T06:00:00Z
    1960-04-03T07:00:00Z
    1960-10-30T06:00:00Z
    1961-04-02T07:00:00Z
    1961-10-29T06:00:00Z
    1962-04-01T07:00:00Z
    1962-10-28T06:00:00Z
    1963-04-07T07:00:00Z
    1963-10-27T06:00:00Z
    1964-04-05T07:00:00Z
    1964-10-25T06:00:00Z
    
    Transitions for America/Toronto
    1959-10-25T06:00:00Z
    1960-04-24T07:00:00Z
    1960-10-30T06:00:00Z
    1961-04-30T07:00:00Z
    1961-10-29T06:00:00Z
    1962-04-29T07:00:00Z
    1962-10-28T06:00:00Z
    1963-04-28T07:00:00Z
    1963-10-27T06:00:00Z
    1964-04-26T07:00:00Z
    1964-10-25T06:00:00Z
    

    There are other time zone IDs which map to “Eastern Standard Time”, but I haven’t found any which match the Windows behaviour.

    I don’t think this is a TimeZoneInfo bug – I believe it’s a potential problem in the underlying Windows time zone data.

    If you want to match TZDB data, of course, you can just use Noda Time 🙂

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

Sidebar

Related Questions

I have some code that will change the background color of a specific label
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have some code here that uses bitsets to store many 1 bit values
I have some arbitrary pixel data that I want to save as a PNG.
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .
I have some tables roughly like so: Client: id name Employee id name Email
i have some problems with a Query seem IN dosen't work with Group_concat, that
ASP.NET 4.0 Need some help with this vexing HTTP POST problem - I have
I realize IDataReader is outdated and some view it as dirty code, but on
I have some data loaded as a np.ndarray and need to convert it to

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.