I am implementing DST checkbox, when checkbox is on clock is adjusted if required and if checkbox is off then DST is not considered,
Suppose When DST begins, clocks are advanced by one hour
so here we have two times - original time and adjusted time
how do I retrieve both these times?
at New York (-04)
On Sun, Mar 8 at 2:00 am
DST starts so clocks are adjusted +1 hour.
so there is original time and adjusted time
at original time Sun, Mar 9 at 8:00 am
the clock displays adjusted time Sun, Mar 9 at 9:00 am
being at a place out of USA, given input as current universal time
I want to retrieve original time
and DST adjusted time
at new york.
Input/Output - Update 03/05
Is this correct way of achieving above
string fromZoneId = "Asia/Kolkata";
string toZoneId = "America/New_York";
var fromDateTime = DateTime.Parse("March 9, 2020");//Input kolkata time
LocalDateTime fromLocal = LocalDateTime.FromDateTime(fromDateTime);
DateTimeZone fromZone = DateTimeZoneProviders.Tzdb[fromZoneId];
ZonedDateTime fromZoned = fromLocal.InZoneLeniently(fromZone);
DateTimeZone toZone = DateTimeZoneProviders.Tzdb[toZoneId];
ZonedDateTime toZoned = fromZoned.WithZone(toZone);
LocalDateTime toLocal = toZoned.LocalDateTime;
var interval = toZoned.GetZoneInterval();
var savings = interval.Savings;
var originalTime = toLocal.ToDateTimeUnspecified().AddSeconds(-savings.Seconds);
var dstAdjustedTime = toLocal.ToDateTimeUnspecified();
Console.WriteLine("Actual:"+ originalTime);//output-dst off
Console.WriteLine("Adjusted:"+ dstAdjustedTime);//output-dst on