Compact Framework中提供了什么API来读取时间(不是UTC !!) 在基于Windows移动设备上?
我能够使用以下代码获取UTC设备时间:
DateTime dt = DateLib.Now;
SystemTime sysTime = new SystemTime();
Windows.SystemTime.GetSystemTime(out sysTime);
Windows.SystemTime.ConvertTimeStructure(ref sysTime, out dt);
Windows.SystemTime.SetSystemTime(dt);
但我希望按照设备的时区来计算时间。 感谢
答案 0 :(得分:1)
为什么不是简单地使用内置的,受支持的DateTime.Now
属性?
修改强>
Compact Framework caches timezone information on load,因此在加载应用程序后更改时区的任何调用都不会反映在对DateTime.Now的调用中。
现在我假设您是P / Invoking GetSystemTime
,而应该是P / Invoking GetLocalTime
。
答案 1 :(得分:1)
您可以使用DateTime.UtcNow获取UTC时间。获取当前的utc偏移量TimeZone
GetUtcOffset以获得TimeSpan。
http://msdn.microsoft.com/en-us/library/system.timezone.getutcoffset.aspx
然后你可以得到LocalTime = DateTime.UtcNow + TimeZone.GetUtcOffset