Am I trying to find the time zone and return the time when using DaylightSavingTime?
Currently I can:
- find time zone
- get utc offset
- calculate local time based on this
- determine if the timezone uses DaylightSavingTime
- get rules for DaylightSavingTime
- determine if current time is using DaylightSavingTime
However, I am having problems applying the rules, here is the code:
Fyi
System.DateTime.Now.ToUniversalTime().Add(timeDiffUtcClient)
return = 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 of localDate of is {2010/07/10 08:20:40 AM}
It should be {2010/07/10 09:20:40 AM}
For some reason, it's 1 hour.