Getting the correct timezone in a web application

English: A timezone indicator showing UTC+6 Ру...

I support a web application that is hosted on a virtual private server. The application architecture is JavaEE running under GlassFish on CentOS.

Like most ISP’s, my hosting provider builds vanilla Linux boxes that can be configured with various flavors of the OS.

Out of the box these images have their timezone set to UTC, and since my end users are in California, and I’m not doing anything on the client to handle timezone conversion, the times that come up in the application are off by 7 or 8 hours (depending on whether it’s Daylight Savings time or not.

To fix this problem, I simply relinked the localtime to the proper timezone file after making sure the timezone data is up to date.

To update the timezone, I run the following:

[root@slice ~]# yum reinstall


Loaded plugins: fastestmirror
Setting up


Determining fastest mirrors
 * base:
 * extras:
 * updates:
base                                                     | 3.7 kB     00:00     
drivesrvr                                                |  951 B     00:00     
drivesrvr/primary                                        | 7.6 kB     00:00     
drivesrvr                                                                 57/57
extras                                                   | 3.4 kB     00:00     
rackspace                                                | 1.3 kB     00:00     
rackspace/primary                                        | 1.5 kB     00:00     
rackspace                                                                   3/3
updates                                                  | 3.4 kB     00:00     
updates/primary_db                                       | 3.1 MB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package tzdata.noarch 0:2014b-1.el6 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

 Package         Arch            Version                 Repository        Size
 tzdata          noarch          2014b-1.el6             updates          449 k

Transaction Summary
Reinstall     1 Package(s)

Total download size: 449 k
Installed size: 1.8 M
Downloading Packages:
tzdata-2014b-1.el6.noarch.rpm                            | 449 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : tzdata-2014b-1.el6.noarch                                    1/1 
  Verifying  : tzdata-2014b-1.el6.noarch                                    1/1 

  tzdata.noarch 0:2014b-1.el6                                                   


Now checking the date, I see the UTC displayed, so I link the right time zone like this:

[root@slice ~]# date
Wed May 21 23:01:11 UTC 2014
[root@slice ~]# ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
[root@slice ~]# date
Wed May 21 16:01:44 PDT 2014

So now the date shows up as Pacific Daylight Time, which is current as of today

Hi, I’m Rob Weaver