How to Set Linux Timezone to CST (Asia/Shanghai) with timedatectl and Manual Methods
This guide explains three ways to change a Linux system's timezone to China Standard Time (CST, Asia/Shanghai) – using the timedatectl command, manually linking /etc/localtime, and setting the TZ environment variable – with step‑by‑step commands and important cautions.
Overview
Linux displays local time according to the configured time zone. To set the system to China Standard Time (CST, GMT+8) you can use one of three approaches: the timedatectl utility (recommended on systemd‑based distributions), a manual symbolic link of /etc/localtime, or a temporary TZ environment variable.
Method 1: Use timedatectl (systemd‑based distributions)
Inspect the current configuration timedatectl The output shows Local time , Universal time and Time zone . A typical line for CST is Time zone: Asia/Shanghai (CST, +0800) .
List available zones (optional) timedatectl list-timezones | grep Shanghai The command should return Asia/Shanghai .
Set the zone to CST sudo timedatectl set-timezone Asia/Shanghai Verify the change timedatectl The Time zone line must now read Asia/Shanghai (CST, +0800) . The system clock itself remains in UTC; only the presentation layer is altered.
Method 2: Manually link /etc/localtime (systems without timedatectl )
Backup the existing file sudo mv /etc/localtime /etc/localtime.bak Create a symbolic link to the CST zone data
sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeConfirm the new setting date The displayed time should correspond to GMT+8.
Method 3: Set the TZ environment variable (session‑wide, temporary)
Export the variable in the current shell: export TZ="Asia/Shanghai" Check the result: date The change lasts only for the lifetime of the shell session; a new terminal or a reboot discards it.
Important Considerations
Prefer timedatectl on modern Linux distributions because it updates the kernel’s clock configuration, the /etc/localtime symlink, and notifies services that rely on time.
Ensure the hardware clock (RTC) is set to UTC. The time zone setting does not affect UTC timestamps used by logs and network protocols.
The manual /etc/localtime method is useful for older, non‑systemd systems (e.g., SysVinit or minimal containers) where timedatectl is unavailable.
Using the TZ variable is suitable for one‑off commands or scripts that must run with a specific zone without altering the host configuration.
Reference: https://www.cnblogs.com/guowenrui/p/18577526
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
