廿八的记录与分享
廿八是个偷懒的搬运工
开小招

如何将Linux时间改为 UTC+8 北京时间的几种方法

1.设置当前系统时间为 UTC+8

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
timedatectl set-timezone Asia/Shanghai
timedatectl set-timezone Asia/Shanghai
timedatectl set-timezone Asia/Shanghai

2.同步时间为北京时间:一般不需要,保险起见,建议还是同步一下

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yum -y install ntpdate
timedatectl set-timezone Asia/Shanghai
ntpdate ntp1.aliyun.com
yum -y install ntpdate timedatectl set-timezone Asia/Shanghai ntpdate ntp1.aliyun.com
yum -y install ntpdate
timedatectl set-timezone Asia/Shanghai
ntpdate ntp1.aliyun.com

3.设置linux系统时间为北京时间

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
1.删除自带的localtime
rm -rf /etc/localtime
2.创建软链接到localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
1.删除自带的localtime rm -rf /etc/localtime 2.创建软链接到localtime ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
1.删除自带的localtime
rm -rf /etc/localtime
2.创建软链接到localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

4.Debian/Ubuntu

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
apt-get install -y ntp
service ntp restart
apt-get install -y ntp service ntp restart
apt-get install -y ntp
service ntp restart

5.CentOS/RHEL

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yum -y install ntpdate
timedatectl set-timezone Asia/Shanghai
ntpdate ntp1.aliyun.com
yum -y install ntpdate timedatectl set-timezone Asia/Shanghai ntpdate ntp1.aliyun.com
yum -y install ntpdate
timedatectl set-timezone Asia/Shanghai
ntpdate ntp1.aliyun.com

执行同步时间的命令后,可以输入 date 查看系统时间是否成功!

赞赏

开小招

如何将Linux时间改为 UTC+8 北京时间的几种方法
1.设置当前系统时间为 UTC+8 timedatectl set-timezone Asia/Shanghai 2.同步时间为北京时间:一般不需要,保险起见,建议还是同步一下 yum -y install ntpdate timedatectl se…
扫描二维码继续阅读
11
2021/06
近期文章