Sunday, February 24, 2019

How does Java manage summertime?




As many of you many know, In Europe we have a summertime and a wintertime. Twice a year, the clocks in all EU Member States are switched from winter to summertime (on the last Sunday in March) and back from summer to wintertime (on the last Sunday in October) (more info here). Now, the European Commision is about to propose to get rid of those clock changes.




In Java, we have Calendars and, a calendar always knows the correct timeZone (i.e. GMT+1 for summertime and GMT+2 for wintertime). How does Java manage this? And, if it's changed, how would it affect to our systems?



So, as I see on comments, there shouldn't be any changes because Java uses System Time and it's setted by NTP, right?


Answer



I will say by java.util.TimeZone .



TimeZone represents a time zone offset, and also figures out daylight savings.
Typically, you get a TimeZone using getDefault which creates a TimeZone based on the time zone where the program is running. For example, for a program running in Japan, getDefault creates a TimeZone object based on Japanese Standard Time.




You can also get a TimeZone using getTimeZone along with a time zone ID. For instance, the time zone ID for the U.S. Pacific Time zone is "America/Los_Angeles". So, you can get a U.S. Pacific Time TimeZone object with:



TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...