Setting default timezone for the JVM of Tomcat

On Linux/Unix: add the "-Duser.timezone=Europe/Budapest" parameter (replacing the "Europe/Budapest" part with the ID of your timezone) to the JAVA_OPTS environment variable in your {TOMCAT_HOME}/bin/startup.sh. If you don't have a line in your startup.sh for setting the JAVA_OPTS, then you can add this to the start of the file (after the shell-specification in the first line of the shell-script, of course Wink ):
export JAVA_OPTS="-Duser.timezone=Europe/Budapest"

On Windows: start the "Configure Tomcat" program from the Start Menu, select the Java tab and add the "-Duser.timezone=Europe/Budapest" to the Java options list.

On both platforms you'll have to restart Tomcat for the new default timezone setting to take effect.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

GREAT TIP !!!!

Thank you so much for this tip

you save my life Smile

Tomcat default timezone on Debian/Ubuntu

As with most packaged software, on Debian/Ubuntu you can set the various default options in the respective file in /etc/defaults. For Tomcat it's the file /etc/defaults/tomcat5.5 and values of the JAVA_OPTS variable can be specified by editing CATALINA_OPTS in this file.

The default CATALINA_OPTS might look like this:
CATALINA_OPTS="-Djava.awt.headless=true -Xmx128M -server"

And adding a default timezone might look like this:
CATALINA_OPTS="-Djava.awt.headless=true -Xmx128M -server -Duser.timezone=Europe/Budapest"

Setting timezone to local time

Hi,

I have setup the time zone and my JVM (in which tomcat runs) works under the same timezone. But I want it to run the JVM on my local time. If I remove the -Duser.timezone option it defaults to the UTC timings.

Do anybody have experience on how to set the time to run on local time?

Appreciate your response.

Thanks,
PG

Re: Setting timezone to local time

I'm not sure I understand your goal. When you wrote "I have setup the time zone", did you mean that you've configured the timezone of your operating system (which is what: windows, linux or mac?)? What do you mean by "my JVM works under the same timezone"? The default timezone (as returned by TimeZone.getDefault()) of your JVM is the same as the one specified for the OS? What do you mean, when you say "I want it to run the JVM on my local time"? How would you tell whether your JVM "runs on your local time" or not? Either I do not get something here or your concept of how the JVM works with timezones, dates, calendars (etc.) is incorrect.

use the following command:

use the following command: sudo dpkg-reconfigure tzdata

Thanks!

Solved my problem! Thank you!

Tomcat and flex/java web app

Dear,
I've read this article and I think to have find the solution but...
I've started Tomcat 7.0 with my web app but the date is wrong! I've started my webapp with Spring server and the date is correct! I've put -Duser.timezone=Europe/Rome (as written in this article) but there's no behaviour difference. Have you some advice for me?!?!

Thanks in advance
Giuseppe

Re: Tomcat and flex/java web app

I need to know more about your environment/setup to be able to help. On what platform are you (Windows, Linux, Mac ... and what version/distribution)? How did you install/setup Tomcat 7 (by downloading a zip or tgz from tomcat.apache.org and extracting it into a directory or using an installer or package management system)? What date is wrong in your webapp? Does the webapp display the current date+time somewhere (on one of it's webpages/URLs) and the displayed date+time does not reflect the operating system's current date+time? How is the date wrong (is it a few hours off from the correct date+time)? What are the timezone settings of the operating system? These are just the basic questions ... if you answer them I'll know what to ask next. Smile

user.timezone with tomcat7

Have you found a solution to your problem in Tomcat7?

I have the same concern with an application under Tomcat7/GWT

Re: user.timezone with tomcat7

Giuseppe did never return to answer my questions, so I could not help him. But if you (Arud) do answer my questions (the same ones I asked Giuseppe), I might be able to help you.

Syndicate content