<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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  • <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>