Linux time and time zones

更新时间:
复制 MD 格式

This topic describes the basic concepts of time and time zones in the Linux operating system, related operations, and changes to the clock configuration in some Alibaba Cloud Linux public images.

Background information

The following table describes the basic concepts of time and time zones in the Linux operating system.

Concept

Description

Clock

Linux has two types of clocks:

  • Hardware clock (real-time clock or RTC): A battery-powered clock on the motherboard. You can set this clock in the Basic Input/Output System (BIOS).

  • System clock: The clock in the Linux kernel. When Linux starts, the system clock is initialized based on the hardware clock and the contents of the /etc/adjtime file. After startup, the system clock runs independently of the hardware clock. The Linux kernel tracks the system clock by counting timer interrupts.

Time standard

Linux has two time standards:

  • localtime: The time standard based on the local time zone of the operating system.

  • Coordinated Universal Time (UTC): A global time standard that is independent of time zones.

Time-related operations

  • Run the following command to view the current time settings.

    timedatectl status

    The command returns information about the local time, UTC, RTC time, and time zone, as shown in the following example.查看时间

  • Use the timedatectl command to set the time standard for the hardware clock.

    • To set the time standard of the hardware clock to localtime:

      timedatectl set-local-rtc 1

      When the time standard of the hardware clock is localtime, the timedatectl status command shows that the value of the RTC in local TZ parameter is yes.

    • To set the time standard of the hardware clock to UTC:

      timedatectl set-local-rtc 0

      When the time standard of the hardware clock is UTC, the timedatectl status command shows that the value of the RTC in local TZ parameter is no.

Note

The /etc/adjtime file is the configuration file for system clock synchronization. Because the preceding commands automatically update the /etc/adjtime file, you do not need to set it separately.

Public images that use the UTC standard for the RTC

By default, the RTC in Alibaba Cloud public images uses the localtime standard. However, in recent public images, Alibaba Cloud changed the default RTC time standard from localtime to UTC. Future versions of these images will continue to use the UTC standard for the RTC. For more information about the release of these public images, see the following documents: