Select And Set TimeZone

摘要:Select And Set TimeZone

顯示所有時區和設定選擇時區,找了很多API試試,大多是設定時區,但沒有二種都有的,只好自已試試,請參考如下:

使用TimeZoneInformation API. 參考http://www.codeproject.com/KB/dotnet/WorldClock.aspx 

第一張為:未設定前可選擇時區

第二張為:已設定時區後,右下角時間已改變

 

於TimeZoneInformation API. 加入方法SetTimeZone、於NativeMethods加入時區設定SetTimeZoneInformation
public static void SetTimeZone(TimeZoneInformation Timezone)
{
            TimeZoneInformation tzi = Timezone;
            TIME_ZONE_INFORMATION tziNative = new TIME_ZONE_INFORMATION();
             tziNative.Bias = tzi.m_tzi.bias;
             tziNative.DaylightBias = tzi.m_tzi.daylightBias;
             tziNative.DaylightName = tzi.DaylightName;
             tziNative.StandardBias = tzi.m_tzi.standardBias;
             tziNative.StandardName = tzi.StandardName;

             NativeMethods.SetTimeZoneInformation(ref tziNative);
}

 [DllImport(KERNEL32)]
 public static extern uint SetTimeZoneInformation([In] ref TIME_ZONE_INFORMATION lpTimeZoneInformation);


 如有不正確、請指教!