3

I have downloaded Tomcat 8 and copied the unzipped folder in my required path. I am using this tomcat as my server while running my web app.

  1. When I access system default time zone using java time package, actually the time zone of what I get. Is it system's clock setting? Or is it tomcat's settings.

  2. Where can I set time zone in tomcat.

4
  • 1
    ... But the answers are independent of operating system ...
    – Marged
    Commented Jan 11, 2016 at 6:40
  • It does not solve my problem. After reading those answers, do you think like it can solve my problem. :(
    – nr.iras.sk
    Commented Jan 11, 2016 at 6:45
  • I have two questions there. First question can be answered right.
    – nr.iras.sk
    Commented Jan 11, 2016 at 6:47
  • 1
    1) By default, the Java Runtime Library uses the Operating Systems timezone. Tomcat doesn't do anything to change that. 2) Linked article has answer: Specify the JVM timezone by setting the value of user.timezone using the -D switch.
    – Andreas
    Commented Jan 11, 2016 at 7:11

1 Answer 1

10
  1. Tomcat uses OS time settings.
  2. Best place is to set environment variables is setenv.bat (setenv.sh) in tomcat bin directory. Use set JAVA_OPTS="-Duser.timezone=GMT" for windows or export JAVA_OPTS="-Duser.timezone=GMT" for linux. Also make sure that catalina.sh contains script to call setenv file. It should be there by default.
8
  • 1
    Is it possible to test whether tomcat time zone is set or not
    – nr.iras.sk
    Commented Jan 11, 2016 at 8:05
  • 1
    Tomcat sets the time of jvm it's running, so you can use <%= new java.util.Date() %> in any jsp file. Or look into catalina.out in log directory it prints lot of information about server startup.
    – aios
    Commented Jan 11, 2016 at 8:18
  • Ok. so the time I get in my Java program is based on what I set there. right? But from java, I always getting time based on my system clock settings
    – nr.iras.sk
    Commented Jan 11, 2016 at 8:20
  • 1
    What you mean by from java? Is java in tomcat server or standalone? If on tomcat it should change, if standalone it will show OS time.
    – aios
    Commented Jan 11, 2016 at 8:29
  • Means, In my system I have installed Java. I downloded tomcat and unzipped it in my D:\ drive. From eclipse I created a Java web project and right click on it. Run as --> Run on Server. Choose the tomcat from D:\ drive. Actually it is just a test API which will display the current time using LocalDateTime.now(). So the API displays my system time in browser.
    – nr.iras.sk
    Commented Jan 11, 2016 at 8:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.