Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Changing timezone on CentOS7

CentOS7 gets shipped with the timedatectl tool which can be used to display/modify timezone settings on the server. There are several options available with this command and you can explore its man page to find out more information.

To list all available timezones, use the timedatectl list-timezones command

Since there are a lot of timezones available, you can use grep command and further filter them: timedatectl list-timezones | grep Europe

Once you’ve chosen a timezone, use timedatectl with the set-timezone parameter to set a particular timezone on your machine:

timedatectl set-timezone Europe/Bucharest

You can view timezone information by typing timedatectl:

Get timezone information on CentOS7

Now if you check out the /etc/localtime file, you will see that it’s actually a symbolic link pointing to the new configured  timezone:

ls -l /etc/localtime 

CentOS timezone

As you can see from the image above, the symlink is pointing to /usr/share/zoneinfo/. If you explore this folder you will see that it contains a directory structure for each locale:

Linux timezone

timedatectl set-timezone command actually creates a that specific symbolic link so you can simply create it manually instead of using this command. So first remove the localtime file and then execute the following command:

ln -s /usr/share/zoneinfo/US/Eastern localtime

In this case the timezone will be changed to US/Eastern so now if we execute timedatectl, you’ll see that the change was made successfully:

How to change timezone on CentOS

TZ environment variable is used to determine local timezone on a machine. If a system is well configured and the timezone is correctly set, it would not be necessary to manually configure this Environment Variable. If you have applications that use it specifically or you have an environment which requires TZ to be set, then, you would need to export it.

Note that tzselect command is available in Centos7 so if you want to change the TZ environment variable you can use this command or export directly the desired value as seen in the following example:

export TZ=:/usr/share/zoneinfo/Europe/London

Changing System locales:

Locales are a method in which a computer is assigned the language, country and codeset for its System.

Linux system locales

With locale -a command you can view all locales that are available to you. If you want to change your locale you can export the following two environment variables with the desired locales:

$ export LANG=en_GB.UTF-8
$ export LC_ALL=en_GB.UTF-8

Note that these will not be persistent changes and you’ll have to add them to your
~/.bashrc or /etc/profile files to make them permanent.




This post first appeared on ITtrainingday | It's All About IT And Much More…, please read the originial post: here

Share the post

Changing timezone on CentOS7

×

Subscribe to Ittrainingday | It's All About It And Much More…

Get updates delivered right to your inbox!

Thank you for your subscription

×