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:
Managing Timezone Data for Java/PHP App Server
Timezone Rules for Java
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, e.g. using the embedded Web SSH client:
2. Once inside, you can check the currently used TZdata version by executing the following string:
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:
As you can see, getting the latest timezone package version for Java-powered server is a really simple operation with Jelastic.
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 9 server.
1. Let’s set the current timestamp to be shown at the server start page - this will help to quickly ensure that new timezone settings have been successfully applied and are relevant for now.For that, paste the code below instead of the /opt/tomcat/webapps/ROOT/index.jsp file default content (the easiest way is to use the inbuilt Jelastic File Manager for that).
<%@page import="java.util.*"%> <html> <head> <title>TZ Page</title> </head> <body> <%=new Date(System.currentTimeMillis()).toString()%> </body> </html>
2. Save the changes and Open your environment in browser with the corresponding button to see the current server time, like:
3. In order to change the actual timezone for a particular server, perform the following:
for Tomcat, TomEE, Payara, Spring Boot and Jetty
Switch to the variables.conf configuration file and add the -Duser.timezone variable with the required zone as a value, for example:
Note: Depending on a particular application server used, the location of this file may vary:
- Tomcat 6, 7, 8, 9, TomEE - /opt/tomcat/conf/variables.conf
- Jetty 6, 8, 9 - /opt/jetty/etc/variables.conf
- Payara 4, 5 - /opt/payara/glassfish/domains/domain1/config/variables.conf
- Spring Boot 1, 2 - /opt/shared/conf/variables.conf
Switch to the /opt/wildfly/bin/standalone.conf file (or, if a server was scaled horizontally, refer to the /opt/wildfly/bin/domain.conf config) 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 new settings.Now, just refresh the server start page or click Open in browser again to see the updated local time:
Timezone Rules for PHP
Managing of the timezone settings at Jelastic PHP application servers (Apache and NGINX) is performed within the [date] section of the main PHP configuration file - php.ini.
As you can see, this section comprises two options, which can be used to:
Updating Timezone RulesThe 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:
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 /var/www/webroot/ROOT/index.php file) with the following code:
<?php 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 specify the desired timezone as a value for the date.timezone parameter within the php.ini file (e.g. Australia/Sydney in our case).
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 corresponds to a required location.