C# 获取本地时区信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18112101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get Local TimeZoneInfo
提问by Nate Pet
I am using C#. I need to get the local time zone info for the person running a web application.
我正在使用 C#。我需要获取运行 Web 应用程序的人的本地时区信息。
I was wondering if:
我想知道是否:
TimeZoneInfo tzinfo = TimeZoneInfo.Local;
TimeZoneInfo.ConvertTimeFromUtc(result.DueDate.Value, tzinfo);
is appropriate. Again depending on what time zone the person running the application is, I would like that to be reflected.
是合适的。再次取决于运行应用程序的人所在的时区,我希望能够反映出来。
采纳答案by Ehsan
yes you are right, this is what you should use. Alternative can be
是的,你是对的,这就是你应该使用的。替代方案可以
TimeZone localZone = TimeZone.CurrentTimeZone;
but the CurrentTimeZone
property corresponds to the TimeZoneInfo.Local
property so no difference really.
但是该CurrentTimeZone
属性对应于该TimeZoneInfo.Local
属性,因此实际上没有区别。
it displays the names for standard time and daylight saving time for the local time zone.
它显示本地时区的标准时间和夏令时名称。