配置本地时间。dpkg-重新配置 tzdata

uni*_*ser 8 scripting debian timezone

我正在使用它来配置本地时间:

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

它是 ncurses 接口。我正在寻找编程的方法。没有用户 ncurses 界面有没有真正的方法?

如何通过一个 shell 命令更改本地时间?

gar*_*Red 12

我假设您想通过一个 shell 命令更改时区。

你有timedatectl你的系统?

如果是这样的话:

timedatectl status 将显示您当前的设置。

timedatectl list-timezones 显示可用的时区。

timedatectl set-timezone Antarctica/Mawson 设置它。

注意:如果 RTC 配置为在本地时间,这也会更新 RTC 时间。


Evg*_*gin 7

有没有真正的方法没有用户 ncurses 界面?

echo Antarctica/Mawson >/etc/timezone
dpkg-reconfigure -f noninteractive tzdata
Run Code Online (Sandbox Code Playgroud)

是的,您可以创建一个 shell 命令:

sh -c 'echo Antarctica/Mawson >/etc/timezone && dpkg-reconfigure -f noninteractive tzdata'
Run Code Online (Sandbox Code Playgroud)

:)

存在一个错误tzdata:某些值通过以下方式标准化dpkg-reconfigure

echo 'US/Central' >/etc/timezone
dpkg-reconfigure -f noninteractive tzdata
# Current default time zone: 'America/Chicago'

echo 'US/Eastern' >/etc/timezone
apt-get install --reinstall tzdata
# Current default time zone: 'America/New_York'
Run Code Online (Sandbox Code Playgroud)

  • 在 16.04 中,您必须设置 `/etc/localtime`,`dpkg-reconfigure` 然后更新 `/etc/timezone`:https://bugs.launchpad.net/ubuntu/+source/tzdata/+bug/1554806 (3认同)