如何在 Debian 中永久重置时区?

ely*_*aie 30 linux time-zone debian-squeeze

Dreamhost 似乎认为我们喜欢 PDT,尽管位于中西部。如何更改时区?

Ynh*_*key 78

我发现一个更容易使用的工具是dpkg-reconfigure. 用:

sudo dpkg-reconfigure tzdata
Run Code Online (Sandbox Code Playgroud)

您将获得多种选择,包括一些未包含在tzselect.


mc0*_*c0e 15

这对于 OP 来说可能有点晚了,更适合到达这里的其他搜索者。

如果您需要非交互式解决方案,请尝试使用 dpkg-reconfigure tzdata 和 debconf-set-selections 更改时区的解决方案

echo "Europe/Zurich" > /etc/timezone 
dpkg-reconfigure -f noninteractive tzdata
Run Code Online (Sandbox Code Playgroud)

您可以通过查看 /usr/share/zoneinfo 来确定您的时区。事实上,上面的 dpkg-reconfigure 命令将适当的文件从那里复制到 /etc/localtime。我以前只是手动执行此操作,它似乎工作正常。

如果长时间运行的进程没有接受更改,请不要太惊讶。例如,Apache 日志时间戳浮现在脑海中。考虑这是否重要,因此是否需要重新启动正在运行的进程甚至重新启动。

  • 请注意,要使其正常工作,要求`/etc/localtime` 不存在。如果它存在并且是到 `/usr/share/zoneinfo/whatever` 的软链接,则将其作为基础,并且相应地更新的是 `/etc/localtime`,覆盖您的更改。 (3认同)

小智 13

要在最近的 Debian 和 Ubuntu 版本(Stretch/Xenial 等)上以非交互方式编辑它,您也需要删除/etc/localtime,否则/etc/timezone将被覆盖。

echo 'Europe/Zurich' > /etc/timezone 
rm /etc/localtime
dpkg-reconfigure -f noninteractive tzdata
Run Code Online (Sandbox Code Playgroud)

这个答案是基于 mc0e' 的答案。我无法用我的声誉添加评论。