Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How do I use `DateTimeOffset`s to show 23 or 25 hours on a day when clocks change?

$
0
0

New York switched from Eastern Standard Time to Eastern Daylight Time on March 10th, 2024.

I believe the time zone ID "Eastern Standard Time" maps to "America/New_York" in .NET.

However, when I cound the number of hours on March 10th, 2024 using this timezone, I see 24 hours and not 23 hours (since clocks moved forward 1 hour at 2am).

(This snippet uses F#, but a C# solution would obviously work too.)

open Systemlet est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")let start = DateTimeOffset(DateTime(2024, 3, 10, 0, 0, 0, DateTimeKind.Unspecified), est.BaseUtcOffset)let stop = DateTimeOffset(DateTime(2024, 3, 11, 0, 0, 0, DateTimeKind.Unspecified), est.BaseUtcOffset)(stop - start).TotalHours# 24.0

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>