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

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

        从 SimpleTimeZone 获取 ZoneId

        Getting ZoneId from a SimpleTimeZone(从 SimpleTimeZone 获取 ZoneId)
          <tfoot id='Chq0f'></tfoot>

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

            • <small id='Chq0f'></small><noframes id='Chq0f'>

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

                  <tbody id='Chq0f'></tbody>
                  本文介绍了从 SimpleTimeZone 获取 ZoneId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 Java,我有一个 SimpleTimeZone 实例,其中包含来自旧系统的 GMT 偏移和夏令时信息.

                  Using Java I have a SimpleTimeZone instance with GMT offset and daylight saving time information from a legacy system.

                  我想检索 ZoneId 以便能够使用 Java 8 时间 API.

                  I would like to retrieve ZoneId to be able to use Java 8 time API.

                  实际上,toZoneId 返回一个没有夏令时信息的 ZoneId

                  Actually, toZoneId returns a ZoneId without the daylight Saving time infos

                  SimpleTimeZone stz = new SimpleTimeZone( 2 * 60 * 60 * 1000, "GMT", Calendar.JANUARY,1,1,1, Calendar.FEBRUARY,1,1,1, 1 * 60 * 60 * 1000);
                  stz.toZoneId();
                  

                  推荐答案

                  这里的解决方案我比较喜欢,因为它很简单,但是你需要一个 Date 和一个 TimeZone 作为参数来检索 ZoneId

                  Here the solution i prefer because it's simple, but you need a Date and a TimeZone as parameters to retrievethe the ZoneId

                  private ZoneId getZoneOffsetFor(final Date date, final TimeZone timeZone){
                    int offsetInMillis = getOffsetInMillis(date, timeZone);
                    return ZoneOffset.ofTotalSeconds( offsetInMillis / 1000 );
                  }
                  
                  private int getOffsetInMillis(final Date date, final TimeZone timeZone){
                    int offsetInMillis = timeZone.getRawOffset();
                    if(timeZone.inDaylightTime(date)){
                       offsetInMillis += timeZone.getDSTSavings();
                    }
                    return offsetInMillis;
                  }
                  

                  这篇关于从 SimpleTimeZone 获取 ZoneId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的游戏框架.有什么建议吗?)
                  • <bdo id='fO9n9'></bdo><ul id='fO9n9'></ul>
                    <tfoot id='fO9n9'></tfoot>

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

                        • <small id='fO9n9'></small><noframes id='fO9n9'>

                            <tbody id='fO9n9'></tbody>