2016-03-04 13 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

不是所问的答案。 –

相关问题