2016-03-04 26 views

回答

12

只需使用TimeZoneInfo.DisplayName屬性:

var zone = TimeZoneInfo.Local; // For example 
Console.WriteLine(zone.DisplayName); 

或者您精確例如:

var zone = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time"); 
Console.WriteLine(zone.DisplayName); // (UTC+07:00) Bangkok, Hanoi, Jakarta 
+0

即使我改變我的電腦的時區。它將打印 (UTC + 07:00)曼谷,河內,雅加達。我想根據個人電腦的時區 – Sachith

+4

@Sithith改變它:如果你手動改變時區的時候你的程序已經在運行,你需要調用'TimeZoneInfo.ClearCachedData()'。這不是你所問的,但我不會將它添加到答案中。 –

-1

我用下面的代碼,以獲得來自不同區域的日期時間。

TimeZoneInfo timeZoneInfo; 

     DateTime dateTime; 

     //Set the time zone information to Australia Standard Time 

     timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Cen. Australia Standard Time"); 

     //Get date and time in Australia Standard Time 

     dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, timeZoneInfo); 

     //Print out the date and time 

     Console.WriteLine(dateTime.ToString("dd-MM-yyyy HH:mm:ss")); 

參考下面這個鏈接更多信息有關時區名稱: http://www.xiirus.net/articles/article-_net-convert-datetime-from-one-timezone-to-another-7e44y.aspx

+1

不是所問的答案。 –

相關問題