0

我正在使用OpenNETCF Smart Device Framework为 Windows Mobile 6.1 开发应用程序,并且我正在尝试使用SetTimeZoneInformation调用从我的应用程序更新 Windows Mobile 设备的时区。

我尝试将其设置为 GMT-5 Eastern(纽约时区,遵守夏令时),但系统选择 GMT-5 Bogota, Lima(不遵守夏令时)。

为了确认我是否设置正确,在设置时区后,我打电话GetTimeZoneInformation查看我之前设置的时区是否匹配并且匹配。所以,我不知道这个设置是如何在内部搞砸的。

我在这里找到了一个类似的问题,但是没有简明的答案,并且有一个已死的引用链接。

这是我正在使用的一些代码:

var tzc = new TimeZoneCollection();
tzc.Initialize();

var currentTz = new TimeZoneInformation();
DateTimeHelper.GetTimeZoneInformation(ref currentTz);

var tziList = tzc.Cast<TimeZoneInformation>().ToList();
var configTzi = tziList.FirstOrDefault(i => i.StandardName == "Eastern Standard Time");

if (configTzi != null)
    if (currentTz.StandardName != configTzi.StandardName)
        DateTimeHelper.SetTimeZoneInformation(configTzi);

任何帮助将不胜感激。

4

1 回答 1

0

您的代码应该可以正常工作,但您说纽约时区遵守夏令时,因此您可能想要启用自动 DST,我可以通过在注册表中使用该代码设置一个键来设置它:

const string key = @"HKEY_LOCAL_MACHINE\Software\Microsoft\Clock";
Registry.SetValue(key, "AutoDST", 1);

希望这会有所帮助,最好的问候

迪迪埃

于 2015-04-29T19:16:23.010 回答