timezone setting

最後更新: 2018-11-15

目錄

  • 設定 timezone(/etc/localtime)
  • 設定 timezone(舊)
  • /etc/timezone
  • Environment Variable - TZ

 


設定 timezone

 

查看 system 的 timezone settings

timedatectl

# 查看 timezone 的可供設定 value

timedatectl list-timezones

# 建立 soft link /etc/localtime -> /usr/share/zoneinfo/Asia/Hong_Kong

timedatectl set-timezone Asia/Hong_Kong

File: /usr/share/zoneinfo/Asia/Hong_Kong

This file holds the actual timezone data

 


設定 timezone(舊)

 

# Debian

方式 1:

tzdata-update

方法 2:

dpkg-reconfigure tzdata

# Centos

方法 3:

rm -f /etc/localtime

ln -s /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime

Notes

ln -sf /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime

 


/etc/timezone

 

# It contains a single line specifying the timezone
# value relative to /usr/share/zoneinfo
# (ls /usr/share/zoneinfo/Asia/Hong_Kong)

echo 'Asia/Hong_Kong' > /etc/timezone

 


Environment Variable - TZ

 

If the environment variable TZ has not been set,
and the timezone file has not been copied into the chroot jail,
then the first attempt to use strftime() causes the timezone to revert to UTC for all future time accesses in the child process.
If one adjusts the config.h so that strftime is not used, the problem disappears.

Set the Timezone by cities

# 要與 /usr/share/zoneinfo/Asia/Hong_Kong 對應

export TZ='Asia/Hong_Kong'; date; unset TZ

Set the Time Zone Using the Posix TZ Format

UTC: Coordinated Universal Time

GMT: Greenwich Mean Time (格林威治標準時間) # 已經被原子鐘報時的協調世界時(UTC)所取代

# This is positive if the local time zone is west of the Prime Meridian and negative if it is east
# 8 hours ahead (east) of UTC
# HK = UTC+08:00

export TZ='UTC-8'; date; unset TZ

 

Creative Commons license icon Creative Commons license icon