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

    • <bdo id='FeQJn'></bdo><ul id='FeQJn'></ul>

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

    2. <tfoot id='FeQJn'></tfoot>

      如何使 java.sql.Timestamp UTC 时间?

      时间:2023-07-25
      <legend id='crwFD'><style id='crwFD'><dir id='crwFD'><q id='crwFD'></q></dir></style></legend>

            <tbody id='crwFD'></tbody>

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

          1. <tfoot id='crwFD'></tfoot>

              <bdo id='crwFD'></bdo><ul id='crwFD'></ul>
              <i id='crwFD'><tr id='crwFD'><dt id='crwFD'><q id='crwFD'><span id='crwFD'><b id='crwFD'><form id='crwFD'><ins id='crwFD'></ins><ul id='crwFD'></ul><sub id='crwFD'></sub></form><legend id='crwFD'></legend><bdo id='crwFD'><pre id='crwFD'><center id='crwFD'></center></pre></bdo></b><th id='crwFD'></th></span></q></dt></tr></i><div id='crwFD'><tfoot id='crwFD'></tfoot><dl id='crwFD'><fieldset id='crwFD'></fieldset></dl></div>
                本文介绍了如何使 java.sql.Timestamp UTC 时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                public static void main(String[] args) {
                
                    LocalDateTime ldt = LocalDateTime.now();
                
                    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
                
                    Instant instant = Instant.from(zdt);
                
                    Timestamp timestamp = Timestamp.from(instant);
                
                    System.out.println(ldt + "
                ");
                
                    System.out.println(zdt + "
                ");
                
                    System.out.println(instant + "
                ");
                
                    System.out.println(timestamp + "
                ");
                }
                

                然后打印出来:

                2017-05-07T18:13:26.969
                
                2017-05-07T18:13:26.969-04:00[America/New_York]
                
                2017-05-07T22:13:26.969Z
                
                2017-05-07 18:13:26.969
                

                如何使 SQL TimestampInstant 的保存时间相同?我需要能够从任何地方获取 Timestamp 并将其转换为它碰巧在世界那个地方的任何时间.问题是它一直保存与我的系统时钟设置的时间相同.

                How can I make an SQL Timestamp save with the same time as the Instant? I need to be able to get the Timestamp from anywhere and convert it to whatever time it happens to be in that part of the world. The problem is that it keeps saving as the same time as whatever my system clock happens to be set at.

                推荐答案

                你最好从 LocalDateTime 中获取 Timestamp,而不是从 Instant.

                You are best to get a Timestamp from a LocalDateTime, rather than from an Instant.

                第一步是获取您的 ZonedDateTime 并将其转换为 GMT:

                The first step is to take your ZonedDateTime and convert it to GMT:

                ZonedDateTime gmt = zdt.withZoneSameInstant(ZoneId.of("GMT"));
                

                然后您可以通过 LocalDateTime 将其转换为 Timestamp:

                Then you can convert it to a Timestamp via a LocalDateTime:

                Timestamp timestamp = Timestamp.valueOf(gmt.toLocalDateTime());
                

                这篇关于如何使 java.sql.Timestamp UTC 时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何将时间戳转换为适当的日期格式? 下一篇:发送数据时,从 Android 应用中的 Firebase 检索 Se

                相关文章

                最新文章

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

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

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