problems with Java daylight savings time

后端 未结 4 1150
长情又很酷
长情又很酷 2021-01-05 01:35

I have a Java app that needs to be cognizant of the time zone. When I take a Unix epoch time and try to convert it into a timestamp to use for an Oracle SQL call, it is get

4条回答
  •  情深已故
    2021-01-05 02:08

    If you want to disable daylight saving calculation, then you must set your timezone to EST. Else otherwise time will be calculated based on default time zone set for AMERICA/NEW_YORK

           TimeZone zoneEST = TimeZone.getTimeZone("EST"); 
           System.out.println(zoneEST.getDSTSavings());  //0 hour
           System.out.println(zoneEST.getRawOffset());  //5 hour
           TimeZone.setDefault(zoneEST);
           System.out.println("");
    
           TimeZone zoneNY = TimeZone.getTimeZone("America/New_York");
           System.out.println(zoneNY.getDSTSavings()); // 1 hour
           System.out.println(zoneNY.getRawOffset()); // 5 hour
    

提交回复
热议问题