Shoaib Khan Khattak
on
July 18, 2020

How to Change TimeZone On Linux Server

Embrace Love: Share Us on Social Media

The Time zone shows the standard time for a specific area or geographic region. How to change the timezone on a Linux server is always a big question. The time zone is set when we install any operating system on our device or on our server. Timezone settings are one of the most important things to cover during installation because they impact our system functionalities. There are many ways to change timezone on Linux server but the most used and easy way is to set using the command line.

In this article, we will discuss how to set or change the timezone on a Linux server using the command line.

1. How to check the Current Time Zone

Before changing the time zone it is important to check the current time zone of your system. Linux system makes it easy to check the current time zone of your system by using the command “timedatectl“. It is available on all modern systems-based Linux systems.

To view the time zone follow the steps:

Open your Linux terminal and run timedatectl command on it

$ timedatectl

The output of the command shows the current timezone of the system. Now you can go for changes if you want to change the current time zone of your system.

Note: this step is not must for changing time zone you can do it after change this is just a good way. So if you have already your required time zone then there is no need to change.

2. Set/Change Timezone on Linux Server Using Command line

Once you check your current time zone and want to change. First, you will need to find the specific name of the time zone you want to use. the specific name is like “Region/city“.

To List, the available time zone use timedatectl list-timezone command

$ timedatectl list-timezones

Now check the required time zone in the list and run the next command which is “sudo timedatectl set-timezone “you time zone” ” the last argument is the your specific time zone you want to set for your system.

sudo ” is used to run administrator rights or root user.

$ sudo timedatectl set-timezone <your specific time zone>

After running this command confirm time zone by running:

$ timedatectl
Change Timezone on Linux server

You can see the required time zone here after changing.

3. Importance of time zone

The time zone is very important for your system as many functionalities depends upon the time zone.

Every geographic part has its own specific time zone. Many things depend upon that like:

  • Access for system may be Bound to specific Time zone or Region.
  • If some record need to store in system it need that specific time zone.
  • In case of online server its important to set specific time zone its import from security point of view.

4. Things to remember

In the case of Linux server and the database of the site attached to that server. There are some issues which we suggest you to remember and check.

After changing the time zone of your system, you need to check your database if it is storing time and date.

If your database is storing old or wrong time and date. Then reboot your system it will fix your issue.

Reboot restart all services of your system and new time zone is ready to store in database.

Changing the Time Zone by Creating a Symlink #

Changing the time zone on a computer is a common task, especially when users move across different regions or need to synchronize their system with a specific time zone. On Unix-like systems, such as Linux, one interesting and unconventional method to achieve this is by creating a symbolic link (symlink) to the desired time zone file.

The time zone information on Unix-like systems is typically stored in the “/usr/share/zoneinfo” directory, and each time zone is represented by a binary file. To change the time zone using a symlink, follow these steps:

  1. Identify the Current Time Zone
    Determine the current time zone of your system before making any changes. You can use the date command with the %Z format specifier to display the current time zone:
    date +"%Z"
  2. Navigate to the Zoneinfo Directory
    The time zone files are stored in the “/usr/share/zoneinfo” directory. Navigate to this directory using the cd command:
    cd /usr/share/zoneinfo
  3. Create a Symlink to the Desired Time Zone
    Use the ln command to create a symbolic link to the binary file representing the desired time zone. For example, if you want to change the time zone to “America/New_York,” you would create a symlink like this:
    ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

    In this command, -s indicates that the link should be symbolic, and -f overwrites the existing symlink if it exists.
  4. Verify the Changes
    Confirm that the time zone has been successfully changed by running the date command again:
    date
    The output should now reflect the new time zone.
  5. Update the System Clock
    It’s a good practice to synchronize the system clock with the hardware clock after changing the time zone. You can use the hwclock command for this:
    hwclock --systohc

    This command updates the hardware clock based on the system time. Using symlinks to change the time zone provides a flexible and efficient way to manage time zone configurations without directly modifying system files. However, it’s crucial to exercise caution and ensure that you select the correct time zone to avoid potential issues with system timekeeping.

FAQs

How can I check the current time zone on my Linux server?

You can use the timedatectl command to display the current system clock settings, including the time zone. Simply type timedatectl in the terminal, and it will provide information about the current time zone.

What are the conventional tools for changing the time zone on a Linux server?

Common tools for changing the time zone include timedatectl and tzselect. The former allows for easy configuration, while the latter provides an interactive menu to select the desired time zone.

What is the advantage of using a symbolic link to change the time zone?

Creating a symbolic link to the desired time zone file in the “/usr/share/zoneinfo” directory offers a flexible and non-intrusive method. It allows for quick adjustments without directly modifying system files, providing an alternative approach to changing the time zone.

Is it necessary to restart the server after changing the time zone?

In most cases, restarting the server is not required. The changes should take effect immediately. However, you may want to restart services or applications that rely on the system time to ensure they use the updated time zone information.

What precautions should I take when changing the time zone on a Linux server?

Ensure you select the correct time zone to avoid potential issues with timekeeping. Additionally, consider updating the hardware clock using the hwclock --systohc command after changing the time zone.

Conclusion

In conclusion, changing the time zone on a Linux server is a straightforward process that can be accomplished using various methods. While system administrators often rely on traditional tools like “timedatectl” or “tzselect,” creating a symbolic link to the desired time zone file in the “/usr/share/zoneinfo” directory provides a unique and effective alternative. This method allows for a seamless adjustment of the system’s time zone without directly modifying system files. Whether opting for conventional tools or the symlink approach, it is essential to choose the appropriate time zone accurately to ensure accurate timekeeping.

Read More: HOW TO TRANSFER A WEBSITE FROM CPANEL TO CYBERPANEL MANUALLY

Follow US on Facebook / Twitter   for update.

10 comments

Leave your comment

Stay in the loop!

If you found this article helpful, join our mailing list to receive CyberHosting updates and latest news from the LiteSpeed community.

  • Only useful information.
  • Relevent to hosting and LiteSpeed.
  • No spam. Ever.

By joining our mailing list you agree to receive periodic communications from CyberHosting. You can unsubscribe from within our emails any time.