TimeZone 類只識別本地時區(qū),但可以在協(xié)調(diào)世界時 (UTC) 和本地時間之間轉(zhuǎn)換時間,。TimeZoneInfo 對象可以表示任意時區(qū),,且 TimeZoneInfo 類的方法可用于將一個時區(qū)的時間轉(zhuǎn)換為其他任意時區(qū)的相應(yīng)時間,。
TimeZoneInfo timeZoneInfoLocal = TimeZoneInfo.Local;
string s = timeZoneInfoLocal.DaylightName + "," + timeZoneInfoLocal.DisplayName + ","
+ timeZoneInfoLocal.Id + "," + timeZoneInfoLocal.StandardName + "," + timeZoneInfoLocal.SupportsDaylightSavingTime;
//獲取本地時間對應(yīng)的標(biāo)準(zhǔn)時間(UTC)
DateTime utc=TimeZoneInfo.ConvertTimeToUtc(DateTime.Now);
//UTC轉(zhuǎn)化為本地時間
DateTime nowTime = TimeZoneInfo.ConvertTimeFromUtc(utc, timeZoneInfoLocal);
//獲取本地時間和UTC之間的差值--時差
TimeSpan utcOffset =TimeZoneInfo.Local.BaseUtcOffset;
TimeSpan utcOffset1 = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);
TimeSpan a = new TimeSpan(10, 0, 0);
TimeZoneInfo timeZoneInfoHawaiian = TimeZoneInfo.CreateCustomTimeZone("Hawaiian Standard Time sss", a, "夏威夷", "Hawaiian");
DateTime hawaiianTime = TimeZoneInfo.ConvertTimeFromUtc(utc, timeZoneInfoHawaiian);