更改Linux系统时间及时区
时区选择:
[root@master-c21 ~]# tzselect
-
Asia
#? 5 -
China
#? 9 -
Beijing Time
-
* Time
#? 1
The following information has been given:
China
Beijing Time
Therefore TZ=‘Asia/Shanghai’ will be used.
Local time is now: Mon May 24 20:31:31 CST 2021.
Universal Time is now: Mon May 24 12:31:31 UTC 2021.
Is the above information OK?
- Yes
- 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
根据上面的提示,接下来开始操作:
[root@master-c21 ~]# date
Mon May 24 08:32:12 EDT 2021
这时候时间还是不对,
在profile文件中添加这一行
[root@master-c21 ~]# vim ~/.bash_profile
TZ=‘Asia/Shanghai’; export TZ
[root@master-c21 ~]# source ~/.bash_profile
[root@master-c21 ~]# date
Mon May 24 20:33:23 CST 2021
时间终于改过来了。
同步网络时间的命令:
ntpdate ntp1.aliyun.com