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

  • <small id='8cfM9'></small><noframes id='8cfM9'>

      • <bdo id='8cfM9'></bdo><ul id='8cfM9'></ul>

        如何在 Android 中设置字符串解析的时区

        How to set the TimeZone for String parsing in Android(如何在 Android 中设置字符串解析的时区)
          <tbody id='3MU2C'></tbody>
          • <bdo id='3MU2C'></bdo><ul id='3MU2C'></ul>
            <legend id='3MU2C'><style id='3MU2C'><dir id='3MU2C'><q id='3MU2C'></q></dir></style></legend>

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

                <small id='3MU2C'></small><noframes id='3MU2C'>

                1. 本文介绍了如何在 Android 中设置字符串解析的时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试解析一个字符串并设置一个时区,但我无法产生想要的结果.

                  I try to parse a String and set a time zone, but I can't produce the desired result.

                  String dtc = "2014-04-02T07:59:02.111Z";
                  SimpleDateFormat readDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
                  Date date = null;
                  try {
                     date = readDate.parse(dtc);
                     Log.d("myLog", "date "+date);
                  } catch (ParseException e) {
                     Log.d("myLog", "dateExcep " + e);
                  }
                  
                  SimpleDateFormat writeDate = new SimpleDateFormat("dd.MM.yyyy, HH.mm"); 
                  writeDate.setTimeZone(TimeZone.getTimeZone("GMT+04:00"));
                  String dateString = writeDate.format(date);
                  

                  在变量dateString"的输出仍然给出时间 07:59:02 ,我想提前 +4 小时,即 11:59:02

                  At the output of the variable "dateString" still gives the time 07:59:02 , and I want to make it +4 hours in advance that is 11:59:02

                  推荐答案

                  您需要指示读取格式化程序将输入解释为 UTC(GMT - 请记住 Z 代表 ISO-8601 格式的 UTC):

                  You need to instruct the read-formatter to interprete the input as UTC (GMT - remember that Z stands for UTC in ISO-8601-format):

                  String dtc = "2014-04-02T07:59:02.111Z";
                  SimpleDateFormat readDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
                  readDate.setTimeZone(TimeZone.getTimeZone("GMT")); // missing line
                  Date date = readDate.parse(dtc);
                  SimpleDateFormat writeDate = new SimpleDateFormat("dd.MM.yyyy, HH.mm");
                  writeDate.setTimeZone(TimeZone.getTimeZone("GMT+04:00"));
                  String s = writeDate.format(date);
                  

                  然后你会得到:

                  02.04.2014, 11.59

                  02.04.2014, 11.59

                  这篇关于如何在 Android 中设置字符串解析的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)

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

                      <legend id='WMkvR'><style id='WMkvR'><dir id='WMkvR'><q id='WMkvR'></q></dir></style></legend>
                        1. <small id='WMkvR'></small><noframes id='WMkvR'>

                            <tbody id='WMkvR'></tbody>
                          • <bdo id='WMkvR'></bdo><ul id='WMkvR'></ul>

                            <tfoot id='WMkvR'></tfoot>