I'm trying to convert a DateTime that is in CST to EST while adjusting for daylight savings. My local machine is on EST. Found this on msdn but user fokasu recommended using DateTimeOffset to adjust for DST, but i dont know how to incorporate that into my code. thanks for any help. this is what i have so far which works, but i dont think it's adjusting for daylight savings.

 DateTime cstTime, utcTime; DateTime estTime; string cstZoneId, estZoneId; TimeZoneInfo cstZone, estZone; estZoneId = "Eastern Standard Time"; cstZoneId = "Central Standard Time"; estZone = TimeZoneInfo.FindSystemTimeZoneById(estZoneId); cstZone = TimeZoneInfo.FindSystemTimeZoneById(cstZoneId); //define d as CST cstTime = d; try { //convert CST to UTC utcTime = TimeZoneInfo.ConvertTimeToUtc(cstTime, cstZone); //convert UTC to EST estTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, estZone); return estTime; } catch (Exception e) { Console.WriteLine(e.Message); } 
12

1 Answer

It is not clear from your question what the problem is; you have not described the results your code produces nor your expected result.

Except for two periods each year, of an hour's duration each, Central and Eastern time are always one hour apart. The exceptions are at the transitions into and out of daylight saving time. At 2 AM EST, on the second Sunday of March, the Eastern time zone's clocks move to 3 AM EDT. For the next 60 minutes, Eastern Time is two hours ahead of Central Time. Then, at 2 AM CST, the Central time zone's clocks move to 3 AM CDT, and the difference returns to one hour.

Similarly, on the first Sunday in November, at 2 AM EDT, clocks are set to 1 AM EST. For the next 60 minutes, the Central zone remains on daylight saving time, so the time in both places is the same. An hour later, the Central zone's clocks move back one hour, and the normal time difference is restored.

Since your times will never fall in either of these periods, you can safely assume that Central times are always one hour before Eastern times.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy