Solving the UTC problem again and again... (Setting default time zone in JVM)

Posted by Johan on Wednesday, July 6, 2011

I the world of weather everything is done according to UTC and this causes problems, time zones always does.

Yesterday I was debugging an error (not related to weather) in a Spring/GWT/Hibernate app where we are scheduling things. Everything works perfect in the development and test environments but as soon as it is deployed to EC2 it fails. I had a hunch that this was time zone related (EC2 servers on Ireland). Some debugging code was added and the problem was found.

Right now the swedish time differs 2 hours because of daylight saving time so solving the problem by just subtracting hours will not work in 3 months.

The solution was easier than expected, we’re running Tomcat and all I had to do was to add a JAVA_OPT (http://muzso.hu/node/3167.
export JAVA_OPTS=“-Duser.timezone=Europe/Stockholm”

Of course this will not work when the customer decides to let people not living in UTC+1 use the application but this is not a problem yet.