Correct time configuration is essential for server management, affecting processes like logging, scheduling, and synchronization. In Linux, the timedatectl command provides a streamlined method for managing and adjusting the system time, making it easy to set or correct server time accurately. In this guide, we’ll explore how to change the server time in Linux using timedatectl, covering different time-related configurations.

Introduction to timedatectl

timedatectl is a command-line utility in Linux that interacts with the systemd-timesyncd or other time synchronization services to configure and manage time settings on a server. This command allows you to:

  • Check current time and time zone settings
  • Set the time and date manually
  • Adjust the time zone
  • Enable or disable NTP synchronization

Checking the Current Server Time

Before making any adjustments, it’s essential to check the current server time to see if any changes are required.

timezone - change the server time
timedatectl

This command displays detailed time-related information, including:

  • Local time
  • Universal Coordinated Time (UTC)
  • Time zone
  • NTP synchronization status

The output will look something like this:

         Local time: Thu 2024-10-29 12:00:00 IST
Universal time: Thu 2024-10-29 06:30:00 UTC
RTC time: Thu 2024-10-29 06:30:00
Time zone: Asia/Kolkata (IST, +0530)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

If your server time or time zone is incorrect, you can easily adjust it with the following steps.

Setting the Local Time

To manually set the local time on your Linux server, use the timedatectl set-time command followed by the date and time in YYYY-MM-DD HH:MM:SS format.

For example, to set the server time to October 30, 2024, at 13:30, you would enter:

timedatectl set-time "2024-10-30 13:30:00"

Note: Make sure to use sudo if you’re not logged in as the root user, as setting the server time requires superuser privileges.

After setting the time, run timedatectl again to confirm the changes:

timedatectl

Change the Server Time Zone

Time zone configuration is crucial, especially for servers supporting users or applications in specific geographic regions. You can list available time zones using:

sudo timedatectl list-timezones
list timezones - change the server time

Scroll or search through the output to find your desired time zone. To set the server to a new time zone, use:

timedatectl set-timezone <Time_Zone>

Replace <Time_Zone> with your chosen time zone, such as Asia/Kolkata or America/New_York.

Example:

timedatectl set-timezone Asia/Kolkata
set time zone

After setting, verify the time zone by running:

timedatectl

Uses of timedatctl command in Linux

The timedatectl command in Linux is a powerful utility for managing date, time, and time zone settings on a system. Its primary functions include viewing and setting the system time, adjusting the time zone, and controlling NTP (Network Time Protocol) synchronization.

1. Displaying Current Time Settings: Running timedatectl without any options shows the local time, UTC, time zone, and NTP synchronization status. This overview helps users quickly check if time settings are correct.

2. Setting Date and Time: With timedatectl set-time, administrators can manually set the system’s date and time using the YYYY-MM-DD HH:MM:SS format. This is useful in situations where precise control of time is required.

3. Adjusting the Time Zone: By listing and setting time zones, timedatectl allows systems to match local times in various geographical areas. This ensures proper time display for servers operating in specific regions.

4. Enabling or Disabling NTP Sync: NTP synchronization keeps the server’s clock accurate by syncing it with network time servers. timedatectl set-ntp true enables this feature, which is crucial for applications and logs that rely on precise time.

In summary, timedatectl is essential for ensuring accurate time management, necessary for server performance and reliability.

Final Thoughts

Using timedatectl to manage your server‘s time and time zone is an efficient way to maintain correct time settings, essential for server performance and accuracy. Proper time configuration ensures smooth logging, scheduling, and time-sensitive applications. With timedatectl, you have a powerful, straightforward tool to handle time adjustments and synchronization, enhancing server stability and reliability.

By following these steps, you should be able to configure and verify the server time, set the correct time zone, and maintain accurate time using timedatectl or contact your hosting provider.