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

    <tfoot id='draFV'></tfoot>

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

        在Java中将本地时间戳转换为UTC时间戳

        时间:2023-07-27
      2. <small id='2BHoA'></small><noframes id='2BHoA'>

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

                  <tfoot id='2BHoA'></tfoot>
                    <tbody id='2BHoA'></tbody>
                • <legend id='2BHoA'><style id='2BHoA'><dir id='2BHoA'><q id='2BHoA'></q></dir></style></legend>

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

                  问题描述

                  我有一个毫秒-since-local-epoch 时间戳,我想将它转换为毫秒-since-UTC-epoch 时间戳.快速浏览一下文档,看起来像这样可以工作:

                  I have a milliseconds-since-local-epoch timestamp that I'd like to convert into a milliseconds-since-UTC-epoch timestamp. From a quick glance through the docs it looks like something like this would work:

                  int offset = TimeZone.getDefault().getRawOffset();
                  long newTime = oldTime - offset;
                  

                  有没有更好的方法来做到这一点?

                  Is there a better way to do this?

                  推荐答案

                  使用 Calendar 获取本地 Epoch 的偏移量,然后将其添加到本地 epoch 时间戳.

                  Use a Calendar to get what the offset was at the local Epoch, then add that to the local-epoch timestamp.

                  public static long getLocalToUtcDelta() {
                      Calendar local = Calendar.getInstance();
                      local.clear();
                      local.set(1970, Calendar.JANUARY, 1, 0, 0, 0);
                      return local.getTimeInMillis();
                  }
                  
                  public static long converLocalTimeToUtcTime(long timeSinceLocalEpoch) {
                      return timeSinceLocalEpoch + getLocalToUtcDelta();
                  }
                  

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

                  上一篇:如何将 java.sql.Timestamp 增加 14 天? 下一篇:java.text.ParseException:无法解析的日期:“Thu Jan 19

                  相关文章

                  最新文章

                • <tfoot id='gl6bc'></tfoot>
                • <legend id='gl6bc'><style id='gl6bc'><dir id='gl6bc'><q id='gl6bc'></q></dir></style></legend>

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

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

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