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

      <tfoot id='QEVJx'></tfoot>

    1. <i id='QEVJx'><tr id='QEVJx'><dt id='QEVJx'><q id='QEVJx'><span id='QEVJx'><b id='QEVJx'><form id='QEVJx'><ins id='QEVJx'></ins><ul id='QEVJx'></ul><sub id='QEVJx'></sub></form><legend id='QEVJx'></legend><bdo id='QEVJx'><pre id='QEVJx'><center id='QEVJx'></center></pre></bdo></b><th id='QEVJx'></th></span></q></dt></tr></i><div id='QEVJx'><tfoot id='QEVJx'></tfoot><dl id='QEVJx'><fieldset id='QEVJx'></fieldset></dl></div>
      <legend id='QEVJx'><style id='QEVJx'><dir id='QEVJx'><q id='QEVJx'></q></dir></style></legend>
        <bdo id='QEVJx'></bdo><ul id='QEVJx'></ul>
    2. Java DateFormat parse() 不尊重时区

      Java DateFormat parse() doesn#39;t respect the timezone(Java DateFormat parse() 不尊重时区)
        <tbody id='goCYW'></tbody>

      <tfoot id='goCYW'></tfoot>
      • <bdo id='goCYW'></bdo><ul id='goCYW'></ul>
        <legend id='goCYW'><style id='goCYW'><dir id='goCYW'><q id='goCYW'></q></dir></style></legend>
          1. <small id='goCYW'></small><noframes id='goCYW'>

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

              • 本文介绍了Java DateFormat parse() 不尊重时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
                df.setTimeZone(TimeZone.getTimeZone("America/New_York"));
                
                try {
                    System.out.println(df.format(cal.getTime()));
                    System.out.println(df.parse(df.format(cal.getTime())));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                

                结果如下:

                2011-09-24 14:10:51 -0400

                2011-09-24 14:10:51 -0400

                2011 年 9 月 24 日星期六 20:10:51 CEST

                Sat Sep 24 20:10:51 CEST 2011

                为什么当我解析从 format() 获得的日期时,它不遵守时区?

                Why when I parse a date I get from format() it doesn't respect the timezone?

                推荐答案

                你正在打印调用 Date.toString()总是使用默认时区.基本上,您不应该将 Date.toString() 用于除调试以外的任何事情.

                You're printing the result of calling Date.toString(), which always uses the default time zone. Basically, you shouldn't use Date.toString() for anything other than debugging.

                不要忘记 Date 没有时区 - 它代表时间的瞬间,以 Unix 纪元以来的毫秒数(1 月的午夜1970 UTC).

                Don't forget that a Date doesn't have a time zone - it represents an instant in time, measured as milliseconds since the Unix epoch (midnight on January 1st 1970 UTC).

                如果您再次使用格式化程序格式化日期,应该会得出与以前相同的答案.

                If you format the date using your formatter again, that should come up with the same answer as before.

                顺便说一句,我建议使用 Joda Time 而不是 Date/Calendar 如果你在 Java 中做大量的日期/时间工作;这是一个非常更好的 API.

                As an aside, I would recommend the use of Joda Time instead of Date/Calendar if you're doing any significant amount of date/time work in Java; it's a much nicer API.

                这篇关于Java DateFormat parse() 不尊重时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)

                    • <bdo id='9vpma'></bdo><ul id='9vpma'></ul>

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

                          <small id='9vpma'></small><noframes id='9vpma'>