Change Timezone in Tomcat
Solution 1
Unless tomcat has a personal TZ environment variable, then it uses /etc/localtime
which on my system is a copy of /usr/share/zoneinfo/America/New_York
.
Tomcat's personal timezone would be specified in its startup script in a form like:
-Duser.timezone=GMT
Solution 2
Here is what I add at beginning of catalina.sh
(after shabang) to change tomcat's timezone:
TOMCAT_TIMEZONE="-Duser.timezone=Europe/Budapest"
CATALINA_OPTS="$CATALINA_OPTS $TOMCAT_TIMEZONE"
And don't forget to restart tomcat to take effect.
Solution 3
As said Eric Wang you may use
TOMCAT_TIMEZONE="-Duser.timezone=Europe/Budapest"
CATALINA_OPTS="$CATALINA_OPTS $TOMCAT_TIMEZONE"
but on CentOS server I didn't find catalina.sh, instead of that I added these variables to /etc/sysconfig/tomcat6, and that's works!
Nyxynyx
Hello :) I have no formal education in programming :( And I need your help! :D These days its web development: Node.js Meteor.js Python PHP Laravel Javascript / jQuery d3.js MySQL PostgreSQL MongoDB PostGIS
Updated on July 09, 2022Comments
-
Nyxynyx almost 2 years
How can I change the timezone in Tomcat? The timezone used by one of the webapps (Solr) is not right (compared to MySQL timestamps), and I think changing Tomcat's timezone will help. Thanks!
-
stark almost 12 yearsWhat user is solr running as, and what is its environment set to?
-
Nyxynyx almost 12 yearsI loaded solr as a tomcat webapp, and tomcat6 is running as user
tomcat
. Tomcat6 is running in CentOS 6.3 on port 8080.
-
-
Nyxynyx almost 12 yearsThe tomcat webapp Solr has its time faster than the time in MySQL/PHP by 4 hours. If tomcat uses
/etc/localtime
shouldn't the time be the same for Solr and MySQL? -
Nyxynyx almost 12 yearsThe time
last_index_time
inDataImporHandler
'sdataimport.properties
is 4 hours ahead of the time used by PHP/MySQL (EDT, America/Newyork). How should I adjust the UTC timezone used by Solr (or Tomcat) -
stark almost 12 yearsCheck any tomcat startup script or config file for CATALINA_OPTS
-
Paige Cook almost 12 yearsAs @stark answered, pass the -Duser.timezone value when starting Tomcat see this... zeentan.com/wp/apache-solr-timezone-issue
-
Nyxynyx almost 12 yearsMost posts say
CATALINA_OPTS
is incatalina.sh
, but no such file exist at/usr/share/tomcat6/bin
. Where else should I define the timezone? raibledesigns.com/rd/entry/change_tomcat_s_timezone -
mlathe about 11 yearsI had the same issue. It turns out for me Java was looking in the
/etc/sysconfig/clock
file. This this for comment for more info -
stark about 11 yearsThen that's an error on Java's part. /etc/sysconfig/clock is being phased out in recent distros. Everything should be using /etc/localtime unless the user overrides it.
-
Matt Smeets almost 6 yearsThis is not necessarily needed in the catalina.sh, when adding it as a system variable this solution will work as well. :thumbsup:
-
VitorMM over 5 yearsThat works! I have no idea why, but adding the timezone directly to
CATALINA_OPTS
does not work, but that works! IsTOMCAT_TIMEZONE
loaded somewhere else? -
Eric over 5 years@vitormm Nowadays I use timestamp as long, thus timezone doesn't matter much any more in most case. But if you are using spring-boot & embedded tomcat, you may have a try of this: javadeveloperzone.com/spring-boot/…