Java HOUR_OF_DAY is different from different systems

I have the same Java code that runs on Windows and Solaris computers. There is a piece of code that gives different results:

Calendar cd = Calendar.getInstance();
int hour = cd.get(Calendar.HOUR_OF_DAY);
int off = cd.get(Calendar.ZONE_OFFSET)/3600/1000;
System.out.println("current hour " + hour + ", zone offset " + off);

If I run this code at 16:15 local time, the Windows machine will return 16 as an hour and the zone offset as 2 (I am in GMT + 2 time zone, and daylight saving time is currently on). On Solaris, I get 15 as an hour and the same zone offset. The "date" command on Solaris shows that the time is correct and shows the correct time zone. Solaris launches Java 1.4 and Windows 1.5, although I'm not sure if that matters. Any ideas why the results are different?

+3
source share
1 answer

, .

Calendar.DST_OFFSET .

+4

Source: https://habr.com/ru/post/1766967/


All Articles