Ubuntu 系统时间更改

查看 Ubuntu 时间的方法

显示当前日期和时间:

date -R

或者

date

设置日期和时间 (需要超级用户权限):

sudo date MMDDhhmmYYYY

修改 Ubuntu 系统时间时区

sudo tzselect
wan@ubuntu:~$ sudo tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
1) Africa                                                            7) Europe
2) Americas                                                          8) Indian Ocean
3) Antarctica                                                        9) Pacific Ocean
4) Asia                                                             10) coord - I want to use geographical coordinates.
5) Atlantic Ocean                                                   11) TZ - I want to specify the timezone using the Posix TZ format.
6) Australia
#? 4
Please select a country whose clocks agree with yours.
 1) Afghanistan              11) Christmas Island         21) Iraq                     31) Lebanon                  41) Qatar                    51) Thailand
 2) Antarctica               12) Cocos (Keeling) Islands  22) Israel                   32) Macau                    42) Russia                   52) Turkmenistan
 3) Armenia                  13) Cyprus                   23) Japan                    33) Malaysia                 43) Réunion                  53) United Arab Emirates
 4) Azerbaijan               14) East Timor               24) Jordan                   34) Mongolia                 44) Saudi Arabia             54) Uzbekistan
 5) Bahrain                  15) French S. Terr.          25) Kazakhstan               35) Myanmar (Burma)          45) Seychelles               55) Vietnam
 6) Bangladesh               16) Georgia                  26) Korea (North)            36) Nepal                    46) Singapore                56) Yemen
 7) Bhutan                   17) Hong Kong                27) Korea (South)            37) Oman                     47) Sri Lanka
 8) Brunei                   18) India                    28) Kuwait                   38) Pakistan                 48) Syria
 9) Cambodia                 19) Indonesia                29) Kyrgyzstan               39) Palestine                49) Taiwan
10) China                    20) Iran                     30) Laos                     40) Philippines              50) Tajikistan
#? 10
Please select one of the following timezones.
1) Beijing Time
2) Xinjiang Time, Vostok
#? 1

The following information has been given:

        China
        Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Selected time is now:   Thu Nov  2 22:02:16 CST 2023.
Universal Time is now:  Thu Nov  2 14:02:16 UTC 2023.
Is the above information OK?
1) Yes
2) No
#? 1

You can make this change permanent for yourself by appending the line
        TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai

以上选择为:Asia->China->Beijing->Yes

(备注:选择序号 4->10->1->1,依次看到选择项是上面的选择就可以了)

复制文件到/etc/localtime 文件夹下,注意权限,执行命令

sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

替换以前的配置文件。

将时间写入 cmos 硬件时钟

在修改时间以后,为防止后期时间错误,修改硬件 CMOS 的时间,执行以下命令

sudo hwclock --systohc

注意:这个步骤非常重要,如果没有这一步,重启后,时区又会发生改变。

ntpdate 命令:用于手动同步时间与 NTP 服务器。

sudo ntpdate NTP SERVER

启用/禁用网络时间同步 (NTP):

sudo timedatectl set-ntp true   # 启用 NTP
sudo timedatectl set-ntp false  # 禁用 NTP

最后验证测试

查看系统时间是否更新为正确时间。这里需要注意 “R” 为大写。

sudo date -R

随着系统版本的不同,可能还有其他命令和配置文件用于管理时间。无论你选择哪个命令,确保你有足够的权限来修改系统时间,并小心操作,以避免对系统产生不良影响。

参考资料:

  • https://blog.csdn.net/weixin_37813152/article/details/128224046
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。
任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。
如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
Linux 相关

安装Ubuntu Server系统后磁盘空间98G没有全部使用的解决方法

2023-10-19 0:55:59

Linux 相关Windows 相关网络相关

ZeroTier使用教程

2023-11-10 14:56:11

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
有新私信 私信列表
搜索