I'm trying to get the difference between an application running on Windows Embedded 7 and UTC time. To do that I have the following piece of code:
TimeZoneInfo utcTimeZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
DateTime localTime = DateTime.Now;
DateTime utcTime = TimeZoneInfo.ConvertTime(localTime, TimeZoneInfo.Local, utcTimeZone);
TimeSpan utcOffset = localTime - utcTime;
This runs fine on my own development PC, running Windows 7. However, when I install my application on a device running Windows Embedded 7, no matter what timezone I set it to, when I run my application,
- The value for
TimeZoneInfo.Local.BaseUtcOffset
is always 00:00. - The
BaseUtcOffset
value in the object returned byTimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time")
is also 00:00 (though this is to be expected). - The
ConvertTime()
function above always returns the current time less one hour. (Kind of not surprised since theTimeZoneInfo.Local.SupportsDaylightSavingsTime
value is always false.)
Should I be using another way that TimeZoneInfo.Local
to get the offset between UTC and the current time zone? I need to include Daylight Savings in this.