Setting the correct timezone on your CentOS system is important to ensure dates and times are displayed accurately. In this comprehensive guide, I‘ll walk through the various methods to view your current timezone, list available timezones, and set a new timezone on CentOS.

Check Current Timezone

Here are a couple ways to check your CentOS system‘s currently configured timezone:

Using timedatectl

The timedatectl command allows you to query and change system time and date settings. To view the current timezone:

timedatectl status

This will print out the currently configured timezone along with additional date/time details.

Using the /etc/localtime Symlink

The file /etc/localtime is actually a symlink that points to a timezone definition file under /usr/share/zoneinfo. You can view where it‘s pointing to determine the current timezone:

ls -l /etc/localtime

This will show which timezone file /etc/localtime is linked to.

List Available Timezones

Before changing the system timezone, it helps to see what options are available.

Using timedatectl

Ask timedatectl to output the list of recognized timezones for your system:

timedatectl list-timezones

This will print out all the available timezone strings that can be used to set a new timezone.

Using tzselect

The tzselect command provides an interactive timezone selection process:

tzselect

It will prompt you to select a geographic region and eventually zone in on the desired timezone. This helps find an appropriate timezone if you‘re unsure what string to use.

Set a New Timezone

Once you know the timezone you want, here‘s how to configure it:

Using timedatectl

To set a new timezone using the timedatectl command:

sudo timedatectl set-timezone America/New_York

Simply replace America/New_York with the timezone string for your desired timezone.

Using tzdata and localtime Symlink

The process involves:

  1. Setting the TZ environment variable in /etc/sysconfig/clock to the desired timezone
  2. Recreating the /etc/localtime symlink to point to the appropriate timezone definition file under /usr/share/zoneinfo

For example, to set the timezone to Eastern Time (America/New_York):

# Edit /etc/sysconfig/clock
sudo vim /etc/sysconfig/clock

# Set the TZ var to your timezone 
TZ=America/New_York

# Recreate the localtime symlink  
sudo ln -sf /usr/share/zoneinfo/$TZ /etc/localtime

This will change both the TZ variable and /etc/localtime to match your new timezone.

Using GUI Tools

If running a desktop environment like GNOME, you can use graphical timezone tools instead:

  1. Go to Settings -> Date & Time
  2. Click on the Time Zone selector to search and select your timezone on the map
  3. The System timezone will update automatically

That covers the main methods for checking and changing timezones on CentOS. Properly setting your timezone is crucial for accurate system date/time tracking and alignment across distributed systems.

Similar Posts