<bdo id='AILKr'></bdo><ul id='AILKr'></ul>
    1. <small id='AILKr'></small><noframes id='AILKr'>

    2. <legend id='AILKr'><style id='AILKr'><dir id='AILKr'><q id='AILKr'></q></dir></style></legend>
        <i id='AILKr'><tr id='AILKr'><dt id='AILKr'><q id='AILKr'><span id='AILKr'><b id='AILKr'><form id='AILKr'><ins id='AILKr'></ins><ul id='AILKr'></ul><sub id='AILKr'></sub></form><legend id='AILKr'></legend><bdo id='AILKr'><pre id='AILKr'><center id='AILKr'></center></pre></bdo></b><th id='AILKr'></th></span></q></dt></tr></i><div id='AILKr'><tfoot id='AILKr'></tfoot><dl id='AILKr'><fieldset id='AILKr'></fieldset></dl></div>

      1. <tfoot id='AILKr'></tfoot>
      2. 如何在夏令时使用 TimeZoneInfo 获取本地时间?

        How to use TimeZoneInfo to get local time during Daylight Saving Time?(如何在夏令时使用 TimeZoneInfo 获取本地时间?)
        • <bdo id='tFyGe'></bdo><ul id='tFyGe'></ul>

            <tfoot id='tFyGe'></tfoot>

                  <tbody id='tFyGe'></tbody>
              1. <small id='tFyGe'></small><noframes id='tFyGe'>

                <i id='tFyGe'><tr id='tFyGe'><dt id='tFyGe'><q id='tFyGe'><span id='tFyGe'><b id='tFyGe'><form id='tFyGe'><ins id='tFyGe'></ins><ul id='tFyGe'></ul><sub id='tFyGe'></sub></form><legend id='tFyGe'></legend><bdo id='tFyGe'><pre id='tFyGe'><center id='tFyGe'></center></pre></bdo></b><th id='tFyGe'></th></span></q></dt></tr></i><div id='tFyGe'><tfoot id='tFyGe'></tfoot><dl id='tFyGe'><fieldset id='tFyGe'></fieldset></dl></div>

                  <legend id='tFyGe'><style id='tFyGe'><dir id='tFyGe'><q id='tFyGe'></q></dir></style></legend>
                1. 本文介绍了如何在夏令时使用 TimeZoneInfo 获取本地时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 DateTimeOffset 来传达任何时区的特定时刻.我不知道如何使用 TimeZoneInfo 来处理夏令时.

                  I'm trying to use DateTimeOffset to convey a specific moment in time across any time zone. I can't figure out how to use TimeZoneInfo to deal with daylight saving time.

                  var dt = DateTime.UtcNow;
                  Console.WriteLine(dt.ToLocalTime());
                  
                  var tz = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
                  var utcOffset = new DateTimeOffset(dt, TimeSpan.Zero);
                  Console.WriteLine(utcOffset.ToOffset(tz.BaseUtcOffset));
                  

                  打印出来:

                  6/2/2010 4:37:19 PM
                  6/2/2010 3:37:19 PM -06:00

                  我在中央时区,我们目前处于夏令时.我正在尝试阅读第二行:

                  I am in the central time zone, and and we are currently in daylight saving time. I am trying to get the second line to read:

                  6/2/2010 4:37:19 PM -05:00

                  BaseUtcOffset 显然不会根据 DST 改变.

                  BaseUtcOffset apparently doesn't change based on DST.

                  我怎样才能用正确的偏移值获得正确的时间?

                  How can I get the the right time with the proper offset value?

                  推荐答案

                  您需要从 TimeZoneInfo 中获取 UtcOffset,然后将其传递给 ToOffset() 方法:

                  You need to get the UtcOffset from the TimeZoneInfo, then pass that to the ToOffset() method:

                  var dt = DateTime.UtcNow;
                  Console.WriteLine(dt.ToLocalTime());
                  
                  var tz = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
                  var utcOffset = new DateTimeOffset(dt, TimeSpan.Zero);
                  Console.WriteLine(utcOffset.ToOffset(tz.GetUtcOffset(utcOffset)));
                  

                  这篇关于如何在夏令时使用 TimeZoneInfo 获取本地时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                    <tbody id='2Oqf6'></tbody>

                  <small id='2Oqf6'></small><noframes id='2Oqf6'>

                      1. <i id='2Oqf6'><tr id='2Oqf6'><dt id='2Oqf6'><q id='2Oqf6'><span id='2Oqf6'><b id='2Oqf6'><form id='2Oqf6'><ins id='2Oqf6'></ins><ul id='2Oqf6'></ul><sub id='2Oqf6'></sub></form><legend id='2Oqf6'></legend><bdo id='2Oqf6'><pre id='2Oqf6'><center id='2Oqf6'></center></pre></bdo></b><th id='2Oqf6'></th></span></q></dt></tr></i><div id='2Oqf6'><tfoot id='2Oqf6'></tfoot><dl id='2Oqf6'><fieldset id='2Oqf6'></fieldset></dl></div>
                          <bdo id='2Oqf6'></bdo><ul id='2Oqf6'></ul>
                          <tfoot id='2Oqf6'></tfoot><legend id='2Oqf6'><style id='2Oqf6'><dir id='2Oqf6'><q id='2Oqf6'></q></dir></style></legend>