4.4 System Date and Time Settings

System time is based on the POSIX time standard, where time is measured as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970. A day is defined as 86400 seconds and leap seconds are subtracted automatically.

Date and time representation on a system can be set to match a specific timezone. To list all of the available timezones, run:

# timedatectl list-timezones

To set the system timezone to match a value returned from the available timezones, you can run:

# timedatectl set-timezone America/Los_Angeles

Substitute America/Los_Angeles with a valid timezone entry.

This command sets a symbolic link from /etc/localtime to point to the appropriate zone information file in /usr/share/zoneinfo/. The setting takes effect immediately. Some long running processes that might use /etc/localtime to detect the current system timezone, may not detect a subsequent change in system timezone until the process is restarted.

Note that timezones are largely used for display purposes or to handle user input. Changing timezone does not change the time for the system clock. You can change the presentation for system time in any console by setting the TZ environment variable. For example, to see the current time in Tokyo, you can run:

# TZ="Asia/Tokyo" date

You can check your system's current date and time configuration by running the timedatectl command on its own:

# timedatectl
      Local time: Thu 2018-10-25 13:11:30 BST
  Universal time: Thu 2018-10-25 12:11:30 UTC
        RTC time: Thu 2018-10-25 12:11:17
       Time zone: Europe/London (BST, +0100)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2018-03-25 00:59:59 GMT
                  Sun 2018-03-25 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2018-10-28 01:59:59 BST
                  Sun 2018-10-28 01:00:00 GMT

To set system time manually, you can use the timedatectl set-time command. For example. you can run:

# timedatectl set-time "2018-10-28 01:59:59"

This command sets the current system time based on the time specified assuming the currently set system timezone. The command also updates the system Real Time Clock (RTC).

Consider configuring your system to use network time synchronization for accurate time-keeping. This can be particularly important when setting up high-availability or when using network-based file systems. See Chapter 13, Network Time Configuration for more information on configuring network time services that use NTP. If you configure an NTP service, enable NTP by running:

# timedatectl set-ntp true

This command enables and starts the chronyd service, if available.