Managing Timezone Data for Java/PHP App Server

All of the Java and PHP application servers at Jelastic are supplied with special timezone packages, which includes data about the history of local time in different locations around the globe and current timezone rules. This information is required for software, running inside the appropriate containers, and is regularly updated within the corresponding server builds in the confines of the newly released Jelastic Platform versions.

Besides that, you have an ability to instantly update the timezone rules manually if necessary, or change the currently used TZ, based on the preferred location. So, below we’ll reveal some specifics of the timezone data management at Jelastic for the app servers of the abovementioned programming languages:

Timezone Rules for Java

The timezone rules within Java compute nodes are delivered by means of the dedicated TZdata package, comprised in each appropriate container. Follow the instructions below in case you need to update it to the latest version or to change the timezone your server is working at.

Updating Timezone Rules

Despite the fact the newest TZdata package edition is integrated to a node during its creation, after some time it becomes outdated due to periodical changing of the intrinsic data. Thus, old containers may require the corresponding updating from time to time (particularly, in order not to be recreated each time this is needed). For that, a special embedded TZUpdater tool is used, intended for keeping your timezone data accurate and up-to-date. It is a fairly simple to use and can be run with a single-line command, you just need to:

1. Connect to your Java environment via SSH and select the corresponding container:

Tip: In the case you haven’t performed similar operations before, you need to:

2. Once inside, you can check the currently used TZdata version by executing the following string:

java -jar /usr/java/utils/tzupdater.jar -V

3. If you’ve observed the corresponding package in the chosen container is outdated, you can update the timezone information using the embedded TZUpdater tool:

java -jar /usr/java/utils/tzupdater.jar -u

As you can see, getting the latest timezone package version for Java is a really simple operation with Jelastic.

Changing Timezone

Now, let’s discover how to check and change the application server’s local time - we’ll consider this on the example of a Tomcat 7 server.

1. Let’s set the current timestamp to be output at the server’s start page for evident displaying of the upcoming configuration changes - just paste the code below instead of the webapps/ROOT/index.jsp file’s default content (use the inbuilt Jelastic Configuration Manager for that).

<%@page import="java.util.*"%>
       <title>TZ Page</title>
       <%=new Date(System.currentTimeMillis()).toString()%>

2. Save the changes and Open your environment in browser with the corresponding button to see current server time, like:

3. In order to change the actual timezone, perform the following:

  • for Tomcat, TomEE and Jetty

Switch to the variables.conf configuration file and add the -Duser.timezone variable with the required zone as a value (find the complete list here), for example:


Note: Depending on a particular application server used, the location of this file may vary:

  • Tomcat, Tomee - /opt/tomcat/conf/variables.conf
  • Tomcat8 - /opt/shared/conf/variables.conf
  • Jetty 6 - /opt/jetty/etc/variables.conf
  • Jetty 8/9 - /opt/shared/conf/etc/variables.conf

  • for GlassFish

Access the GF admin panel, go to the Configurations > gfcluster-config (or server-config for GF 4) > JVM Settings > JVM Options section and click the Add JVM Option button. Paste the corresponding string within the appeared input field:

  • for JBoss

Navigate to the /opt/shared/bin/standalone.conf file and add the abovementioned variable to the Java VM options section (approximately at the 75th string, right before the closing quotation mark):

  • for Wildfly

Switch to the /opt/shared/bin/standalone.conf configuration file and declare the corresponding variable using the following format:

<export JAVA_OPTS="-Duser.timezone=US/Pacific">

4. Save the made adjustment and Restart your application server in order to apply the new settings. Now, just refresh the server start page or click Open in browser again to see the updated local time:

Great, new rules were applied successfully. In such a way, you can set any desired time location for your server without any problems, in a matter of a minutes.

Timezone Rules for PHP

Management of the timezone settings at Jelastic PHP application servers is performed within the [date] section of the main PHP configuration file - php.ini. Thus, in order to change them, you need to click the Config button next to the required node, locate the appropriate file within the list at the opened tab and scroll down to approximately the 261st line:

As you can see, this section comprises two options, which can be used for binding the external timezone DB in order to get the latest timezone data or setting the required timezone to be used at your server.

Updating Timezone Rules

The first setting allows you to use the alternative external timezone database (namely - the Olson one) in case the internal one is outdated.

For that, simply uncomment the appropriate extension through removing the first semicolon symbol, Save the made alteration and Restart your app server.

Now, if you click Open in browser and scroll until the date section of the opened phpinfo() page, you’ll see the latest timezone package version listed, with the denotation the external DB is used:

Changing Timezone

The second option in the [date] section is intended for defining the current timezone location (by default it points to the UTC zone) of a node. For showing this on a real example, we’ll modify the default server’s start page (the webroot/ROOT/index.php file) with the following code:

echo date("h:i:sa");

Now, if Saving the updated file and clicking Open in browser, you’ll see the timestamp output:

Return to the Jelastic dashboard and edit the date.timezone parameter within the same file with the desired value, picking it from the list of the supported ones (e.g. Australia/Sydney).

Again, Save your new configurations, Restart the corresponding PHP compute node and refresh the page with current time shown:

That’s it! As you can see, the timezone was successfully changed and now represents a different location.