Change Timezone in Tomcat

38,052

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!

Share:
38,052
Nyxynyx
Author by

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, 2022

Comments

  • Nyxynyx
    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
      stark almost 12 years
      What user is solr running as, and what is its environment set to?
    • Nyxynyx
      Nyxynyx almost 12 years
      I loaded solr as a tomcat webapp, and tomcat6 is running as user tomcat. Tomcat6 is running in CentOS 6.3 on port 8080.
  • Nyxynyx
    Nyxynyx almost 12 years
    The 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
    Nyxynyx almost 12 years
    The time last_index_time in DataImporHandler's dataimport.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
    stark almost 12 years
    Check any tomcat startup script or config file for CATALINA_OPTS
  • Paige Cook
    Paige Cook almost 12 years
    As @stark answered, pass the -Duser.timezone value when starting Tomcat see this... zeentan.com/wp/apache-solr-timezone-issue
  • Nyxynyx
    Nyxynyx almost 12 years
    Most posts say CATALINA_OPTS is in catalina.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
    mlathe about 11 years
    I 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
    stark about 11 years
    Then 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
    Matt Smeets almost 6 years
    This is not necessarily needed in the catalina.sh, when adding it as a system variable this solution will work as well. :thumbsup:
  • VitorMM
    VitorMM over 5 years
    That works! I have no idea why, but adding the timezone directly to CATALINA_OPTS does not work, but that works! Is TOMCAT_TIMEZONE loaded somewhere else?
  • Eric
    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/…