[英]How to get time zone as a String in C# ?
我需要以下面的格式获得PC的时区。
(UTC + 07:00)曼谷,河内,雅加达
我怎么能把它作为一个字符串?
只需使用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
我使用下面的代码来获取不同区域的日期时间。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.