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

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

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

      2. 将 UTC 日期转换为其他时区

        Converting UTC dates to other timezones(将 UTC 日期转换为其他时区)

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

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

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

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

                  问题描述

                  限时送ChatGPT账号..

                  我正在使用这种方法将 UTC 时间转换为另一个时区:

                  I'm converting a UTC time to another timezone, using this method:

                  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                  Date parsed = format.parse("2011-03-01 15:10:37");
                  TimeZone tz = TimeZone.getTimeZone("America/Chicago");
                  format.setTimeZone(tz);
                  
                  String result = format.format(parsed);
                  

                  所以输入是 2011-03-01 15:10:37 但是这个(结果的值)的输出是 2011-03-01 05:40:37代码>.虽然它似乎关闭,但根据 此链接,它应该是 2011-03-01 09:10:37.

                  So the input is 2011-03-01 15:10:37 but the output of this (value of result) is 2011-03-01 05:40:37. While it seems off, and according to this link, it should be 2011-03-01 09:10:37.

                  我做错了什么?

                  推荐答案

                  原来代码几乎是正确的,我没有考虑到在解析 String 时得到一个Date 对象最初,它使用默认系统 TimeZone,所以源日期不是我预期的 UTC.

                  It turns out the code was almost correct, what I didn't take into account was that when parsing the String to get a Date object initially, it uses default system TimeZone, so the source date was not in UTC as I expected.

                  诀窍是在将日期解析为 UTC 时设置时区,然后将其设置为目标 TimeZone.像这样的:

                  The trick was to set the timezone when parsing the date to UTC and then set it to destination TimeZone. Something like this:

                  SimpleDateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                  sourceFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
                  Date parsed = sourceFormat.parse("2011-03-01 15:10:37"); // => Date is in UTC now
                  
                  TimeZone tz = TimeZone.getTimeZone("America/Chicago");
                  SimpleDateFormat destFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                  destFormat.setTimeZone(tz);
                  
                  String result = destFormat.format(parsed);
                  

                  这篇关于将 UTC 日期转换为其他时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                  cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  Android file copy(安卓文件拷贝)
                  Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)
                  <legend id='pUovx'><style id='pUovx'><dir id='pUovx'><q id='pUovx'></q></dir></style></legend>
                    <bdo id='pUovx'></bdo><ul id='pUovx'></ul>

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

                          <tfoot id='pUovx'></tfoot>