• <legend id='17dfF'><style id='17dfF'><dir id='17dfF'><q id='17dfF'></q></dir></style></legend>

      <tfoot id='17dfF'></tfoot>

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

          <bdo id='17dfF'></bdo><ul id='17dfF'></ul>

        <small id='17dfF'></small><noframes id='17dfF'>

        将 UTC 日期时间转换为本地日期时间

        时间:2023-10-12
          <tbody id='QqXio'></tbody>

        <small id='QqXio'></small><noframes id='QqXio'>

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

                <legend id='QqXio'><style id='QqXio'><dir id='QqXio'><q id='QqXio'></q></dir></style></legend>

                • 本文介绍了将 UTC 日期时间转换为本地日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我从服务器得到一个日期时间变量,格式如下:6/29/2011 4:52:48 PM,它是 UTC 时间.我想使用 JavaScript 将其转换为当前用户的浏览器时区.

                  From the server I get a datetime variable in this format: 6/29/2011 4:52:48 PM and it is in UTC time. I want to convert it to the current user’s browser time zone using JavaScript.

                  如何使用 JavaScript 或 jQuery 做到这一点?

                  How this can be done using JavaScript or jQuery?

                  推荐答案

                  在我看来,服务器在一般情况下应始终以标准化 ISO 8601 格式返回日期时间.

                  In my point of view servers should always in the general case return a datetime in the standardized ISO 8601-format.

                  更多信息在这里:

                  • http://www.w3.org/TR/NOTE-datetime
                  • https://en.wikipedia.org/wiki/ISO_8601

                  在这种情况下,服务器将返回 '2011-06-29T16:52:48.000Z',这将直接输入 JS Date 对象.

                  IN this case the server would return '2011-06-29T16:52:48.000Z' which would feed directly into the JS Date object.

                  var utcDate = '2011-06-29T16:52:48.000Z';  // ISO-8601 formatted date returned from server
                  var localDate = new Date(utcDate);
                  

                  localDate 将是正确的本地时间,在我的情况下是两个小时后(DK 时间).

                  The localDate will be in the right local time which in my case would be two hours later (DK time).

                  真的不必进行所有这些只会使事情复杂化的解析,只要您与服务器期望的格式一致.

                  You really don't have to do all this parsing which just complicates stuff, as long as you are consistent with what format to expect from the server.

                  这篇关于将 UTC 日期时间转换为本地日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在量角器中正确使用页面对象模式 下一篇:创建具有设定时区的日期而不使用字符串表示

                  相关文章

                  最新文章

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

                  <small id='6nXz8'></small><noframes id='6nXz8'>

                  1. <tfoot id='6nXz8'></tfoot><legend id='6nXz8'><style id='6nXz8'><dir id='6nXz8'><q id='6nXz8'></q></dir></style></legend>
                      <bdo id='6nXz8'></bdo><ul id='6nXz8'></ul>