How to change timezone on a Linux server

Time Zone
Image by deckhand – CC BY-NC-ND 2.0

Every year in March and in October the clock changes in most countries for energy saving purposes. This has the annoying effect of messing up the current time on your server if the timezone is not set properly. Servers in Europe are often set up to UTC time. For example my web hosting provider explicitly says:

Note that any times specified are executed in the timezone of the server, and not your local timezone. Accordingly, you may need to make allowance for this when selecting when to run your cron job. Our servers run in the ‘UTC’ timezone because our client base is global, and it remains constant throughout the year with no changes for daylight saving.

This is a bit annoying for cron jobs as you need to do some calculations in case you want to run them at a specific local time.

Even if you don’t have sudo rights on your server, you can at least modify the time for a given user. For example, to change the timezone for the current user to a local time (e.g.  Europe/London)  run the following command and add it to your bash_profile to make the change permanent:

export TZ="Europe/London"

If you have full control on your server, you can change the timezone system-wide by symlinking /etc/localtime to the appropriate file in /usr/share/zoneinfo. For example, to set the timezone system-wide to the local time in Paris:

ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime

If you run Red Hat/CentOS, you may also need edit /etc/sysconfig/clock in a similar way.

Leave a Reply

Your email address will not be published. Required fields are marked *