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"

This worked for me

This worked for me but I was unable to change jvm properties on ubuntu 20 that show timezone as IST but my java application was not synching with the system time.

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

Thank you

sudo dpkg-reconfigure tzdata
fixed the same probelm on my system too...
Thanks for the tip

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.

Default timezone setting not take effort.

Hi,

The below timezone setting not take effort even after twice restart the tomcat service.
Start the "Configure Tomcat" program from the Start Menu, select the Java tab and add the "-Duser.timezone=Asia/Singapore" to the Java options list.

Re: Default timezone setting not take effort

That's strange. Unfortunately I cannot tell you why it doesn't take effect. Imho it should. Shock If you can figure it out on your own, please leave a comment about it so others can get a clue on a possible pitfall.

Timezone setting

My issue for the timezone setting is resolved after I added the env variable as suggested. Our env is Linux and the file setenv.sh is the one that I updated in /tomcat/bin dir
JAVA_OPTS=-Duser.timezone=CST6CDT
export JAVA_OPTS

Then I stopped and restarted the Tomcat.
The variable took effect and my issue is resolved.