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

  • <tfoot id='zFeEJ'></tfoot>
      <bdo id='zFeEJ'></bdo><ul id='zFeEJ'></ul>

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

      1. 以小时为单位获取时区差异

        时间:2023-10-11

          <small id='4TXGj'></small><noframes id='4TXGj'>

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

                  本文介绍了以小时为单位获取时区差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想通过 Node.js moment 模块获取纽约和香港之间的时区差异.我已经做了一些前期工作.

                  I would like to get the timezone difference between New York and Hong Kong with Node.js moment module. I have done some preliminary work.

                  var NewYork_time_hr = moment().tz("America/New_York").format('HH'); 
                  var HongKong_time_hr = moment().tz("Asia/Hong_Kong").format('HH');
                  

                  然后我可以继续编写一个函数来计算两个时区之间的时间差(以小时为单位).我希望有一个更简单的方法.

                  I can then proceed to write a function to calculate the difference between the 2 timezones in hours. I was hoping for a simpler method.

                  有没有更优雅、更简单的方式来使用矩库?

                  Is there a more elegant and simpler way to do it with moment library?

                  推荐答案

                  不确定更简单",但更正确(因为并非所有时区都相隔一小时):

                  Not sure about "simpler", but more correct (since not all timezones are a full hour from each other):

                  // get the current time so we know which offset to take (DST is such bullkitten)
                  var now = moment.utc();
                  // get the zone offsets for this time, in minutes
                  var NewYork_tz_offset = moment.tz.zone("America/New_York").offset(now); 
                  var HongKong_tz_offset = moment.tz.zone("Asia/Hong_Kong").offset(now);
                  // calculate the difference in hours
                  console.log((NewYork_tz_offset - HongKong_tz_offset) / 60);

                  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
                  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.4.1/moment-timezone-with-data-2010-2020.min.js"></script>

                  这篇关于以小时为单位获取时区差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在Javascript中获取时区的UTC偏移量 下一篇:格式化谷歌图表日期时间轴标签的时区

                  相关文章

                  最新文章

                  1. <small id='DImkq'></small><noframes id='DImkq'>

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

                        <bdo id='DImkq'></bdo><ul id='DImkq'></ul>