查看时间
#查看系统时间 - 12 小时制
root@ubuntu20:/# date Wed 01 Sep 2021 11:51:26 PM CST
#查看系统时间 - 24 小时制
root@ubuntu20:/# date -R Wed, 01 Sep 2021 23:51:29 +0800
#查看硬件时间
root@ubuntu20:/# hwclock --show 2021-09-02 00:16:11.773346+08:00
root@ubuntu20:/#
时间自动更新设置
查看
root@ubuntu20:~# timedatectl show Timezone=Etc/UTC LocalRTC=no CanNTP=yes NTP=no NTPSynchronized=no TimeUSec=Thu 2021-09-02 00:08:33 CST RTCTimeUSec=Thu 2021-09-02 00:08:36 CST
root@ubuntu20:~#
NTP=no 表示时间的自动更新是关闭的
NTP=yes 表示时间的自动更新是开启的
关闭
root@ubuntu20:~# timedatectl set-ntp no
root@ubuntu20:~# timedatectl show Timezone=Etc/UTC LocalRTC=no CanNTP=yes NTP=no NTPSynchronized=no TimeUSec=Thu 2021-09-02 00:12:00 CST RTCTimeUSec=Thu 2021-09-02 00:12:04 CST
root@ubuntu20:~#
打开
root@ubuntu20:~# timedatectl set-ntp yes
root@ubuntu20:~# timedatectl show Timezone=Etc/UTC LocalRTC=no CanNTP=yes NTP=yes NTPSynchronized=yes TimeUSec=Wed 2021-09-01 11:16:47 CST RTCTimeUSec=Wed 2021-09-01 11:16:46 CST
root@ubuntu20:~#
系统时区列表
timedatectl list-timezones
设置时区
sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
时区文件目录 /usr/share/zoneinfo
root@ubuntu20:/etc# cd /usr/share/zoneinfo root@ubuntu20:/usr/share/zoneinfo# ls Africa Asia Canada Cuba EST Factory GMT+0 Hongkong Iran Japan Libya MST NZ-CHAT posix right SystemV Universal W-SU America Atlantic CET EET EST5EDT GB GMT-0 HST iso3166.tab Kwajalein localtime MST7MDT Pacific posixrules ROC Turkey US zone1970.tab Antarctica Australia Chile Egypt Etc GB-Eire GMT0 Iceland Israel leapseconds MET Navajo Poland PRC ROK tzdata.zi UTC zone.tab Arctic Brazil CST6CDT Eire Europe GMT Greenwich Indian Jamaica leap-seconds.list Mexico NZ Portugal PST8PDT Singapore UCT WET Zulu
root@ubuntu20:/usr/share/zoneinfo# cd Asia root@ubuntu20:/usr/share/zoneinfo/Asia# ls Aden Ashkhabad Beirut Chungking Dushanbe Hovd Kamchatka Krasnoyarsk Makassar Oral Rangoon Singapore Thimbu Urumqi Yerevan Almaty Atyrau Bishkek Colombo Famagusta Irkutsk Karachi Kuala_Lumpur Manila Phnom_Penh Riyadh Srednekolymsk Thimphu Ust-Nera Amman Baghdad Brunei Dacca Gaza Istanbul Kashgar Kuching Muscat Pontianak Saigon Taipei Tokyo Vientiane Anadyr Bahrain Calcutta Damascus Harbin Jakarta Kathmandu Kuwait Nicosia Pyongyang Sakhalin Tashkent Tomsk Vladivostok Aqtau Baku Chita Dhaka Hebron Jayapura Katmandu Macao Novokuznetsk Qatar Samarkand Tbilisi Ujung_Pandang Yakutsk Aqtobe Bangkok Choibalsan Dili Ho_Chi_Minh Jerusalem Khandyga Macau Novosibirsk Qostanay Seoul Tehran Ulaanbaatar Yangon Ashgabat Barnaul Chongqing Dubai Hong_Kong Kabul Kolkata Magadan Omsk Qyzylorda Shanghai Tel_Aviv Ulan_Bator Yekaterinburg
root@ubuntu20:/usr/share/zoneinfo/Asia#
设置系统时间
#设置系统时间
date -s "2021-09-01 23:50:00"
#将系统时间同步到硬件时间
hwclock --systohc