Conversion to/from UTC issues

  • Thread starter Thread starter Marina Levit
  • Start date Start date
M

Marina Levit

Hi,

I was getting odd results using ToLocalTime or ToUniversalTime on DateTime
objects - everything kept being off by 4 hours, not 5.

For example, timezone.CurrentTimeZone.GetUtcOffset(dt).TotalHours is always
equal to -4, not -5 (I'm on the east coast of the US). If I check my time
zone settings in windows, of course it says that I am -5 hours, which is
correct.

Incidentally, another issues is that if I call dt = DateTime.SpecifyKind(dt,
DateTimeKind.Local), the date coming back always has Kind= Unspecified,
never what I actually pass it. It just ignores the DateTimeKind entirely.

So, the GetUtcOffset result explains why everything is off by 4 and not 5 -
but the question is, why is that? It's like it is not taking into account
the whole daylight savings time business.
 
Ok, I figured out the first issue - the dates in question are before the
daylights savings time change, so the differential is correct. Dur.

Don't know the issue with the SpecifyKind bit, but oh well, not an issue
anymore I guess.
 
Back
Top