ubuntu:设置系统时间(北京时间)

查看当前时间

root@localhost:~# date
Thu Jul 21 20:26:16 UTC 2022

从输出中可以看到我们现在使用的UTC时间。

设置时区

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

The following information has been given:

    China
    Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Selected time is now:    Fri Jul 22 04:29:53 CST 2022.
Universal Time is now:    Thu Jul 21 20:29:53 UTC 2022.
Is the above information OK?
1) Yes
2) No
#? Yes
Please enter a number in range.
#? 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

# 选择成功之后,可以执行以下命令,重新登录shell即可生效:
$ sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 最后,使用命令date在查看一下当前时间,时区变成了CST(China Standard Time)
$ date

Fri Jul 22 04:29:53 CST 2022

同步到硬件

root@localhost:~# hwclock --systohc

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

技术探索者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值