Hello I'm trying to Find a timezone and return time with DaylightSavingTime applied?
Currenty I can:
- find the time zone
- get utc offset
- calculate the local time based on that
- determine if the time zone uses DaylightSavingTime
- get the rules for DaylightSavingTime
- determine if the current time uses DaylightSavingTime
However I'm having issues applying the rules, here's the code:
fyi
System.DateTime.Now.ToUniversalTime().Add(timeDiffUtcClient)
returns = 2010/07/10 09:25:45 AM
DateTime localDate = System.DateTime.Now.ToUniversalTime();
// Get the venue time zone info
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
TimeSpan timeDiffUtcClient = tz.BaseUtcOffset;
localDate = System.DateTime.Now.ToUniversalTime().Add(timeDiffUtcClient);
if (tz.SupportsDaylightSavingTime && tz.IsDaylightSavingTime(localDate))
{
localDate = localDate.Subtract(tz.GetAdjustmentRules().Single(r => localDate >= r.DateStart && localDate <= r.DateEnd).DaylightDelta);
}
DateTimeOffset utcDate = localDate.ToUniversalTime();
return localDate;
The final value localDate of is {2010/07/10 08:20:40 AM}
It should be {2010/07/10 09:20:40 AM}
It's 1 hour off for some reason.