Java daylight saving seems to be wrong

≡放荡痞女 提交于 2020-01-05 05:53:58

问题


I've been facing some issues with timezone with Java since yesterday (21/10/2018). Looks like java is considering that daylight saving have taken place in Brazil but it hasn't.

I created the following test to be sure

public static void main(String[] args) {

    ZonedDateTime dateTime = LocalDateTime.now().atZone(ZoneId.systemDefault());
    System.out.println(dateTime);

    ZonedDateTime saoPaulo = dateTime.withZoneSameInstant(ZoneId.of("America/Sao_Paulo"));
    ZonedDateTime cuiba = dateTime.withZoneSameInstant(ZoneId.of("America/Cuiaba"));
    ZonedDateTime rightTime = dateTime.withZoneSameInstant(ZoneId.of("GMT-4"));
    System.out.println(saoPaulo);
    System.out.println(cuiba);
    System.out.println(rightTime);
}

That gave the following output

    2018-10-22T09:55:34.473-02:00[America/Sao_Paulo]
    2018-10-22T09:55:34.473-02:00[America/Sao_Paulo]
    2018-10-22T08:55:34.473-03:00[America/Cuiaba]
    2018-10-22T07:55:34.473-04:00[GMT-04:00]

That's wrong as the current timezone to São Paulo should be -03 and America/Cuiaba should be -04

Anyone knows what's the source of the timezone information on Java? There is something I can do on my side to fix that? I know that I can fix it by setting a fixed GMT offset but I'm not fond of it.


回答1:


The link posted by Jon Skeet helped me to solve my issue. Oracle had updated the daylight savings information on latest releases. After updating JDK version, it's working as expected.

    2018-10-22T09:19:31.761-03:00[America/Sao_Paulo]
    2018-10-22T09:19:31.761-03:00[America/Sao_Paulo]
    2018-10-22T08:19:31.761-04:00[America/Cuiaba]
    2018-10-22T08:19:31.761-04:00[GMT-04:00]


来源:https://stackoverflow.com/questions/52928931/java-daylight-saving-seems-to-be-wrong

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!