温馨提示×

debian怎样替换时区设置

小樊
45
2026-09-20 06:06:04
栏目: 智能运维

在 Debian 系统中,替换(修改)时区设置有多种方法,下面按推荐程度由高到低介绍。


方法一:使用 timedatectl(推荐,systemd 系统)

大多数现代 Debian(8 及以后)都使用 systemd。

查看当前时区

timedatectl

列出可用时区

timedatectl list-timezones

设置时区(例如中国标准时间)

sudo timedatectl set-timezone Asia/Shanghai

验证

date

方法二:使用 dpkg-reconfigure

适合不熟悉命令行的用户。

sudo dpkg-reconfigure tzdata
  • 选择 Geographic area
  • 选择具体 Time zone
  • 确认后自动生效

方法三:手动替换 /etc/localtime(传统方式)

删除旧链接

sudo rm -f /etc/localtime

创建新链接(以上海为例)

sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

(可选)写入 /etc/timezone

echo "Asia/Shanghai" | sudo tee /etc/timezone

常见时区示例

地区 时区
中国 Asia/Shanghai
香港 Asia/Hong_Kong
东京 Asia/Tokyo
纽约 America/New_York
UTC UTC

验证是否成功

date
ls -l /etc/localtime

如果你是在 Docker / 容器 / 无 systemd 环境,可以告诉我,我可以给你更合适的方案。

0