What is the best way to set the time zone in Tomcat for a single web app? I\'ve seen options for changing the command-line parameters or environment variables for Tomcat, but is
EDIT: I was wrong about this. This edit corrects it.
The answer is that you cannot portably set the (default) timezone for a single webapp. But if you are using Java 6 (at least), the java.util.TimeZone
class implements the default timezone methods getDefault()
, setDefault()
and setDefault(TimeZone)
using an inheritable thread local. In other words, calling setDefault()
only affects the current thread and future child threads.
The behaviour is not documented in the Sun Javadocs. It works for Java 6 and 5 (see above), but there are no guarantees it will work in older or newer Sun JREs. However, I would be very surprised if Sun decided to change/revert to a 'global' model for the default TimeZone. It would break too many existing applications, and besides globals are BAD.