1.手动修改(缺点:有偏差)
使用date查看当前时间
date -s 时分秒:修改时间 eg:date -s 8:10:10
date -s 完整时间YYYY-MM-DD hh:mm[:ss] eg: "2018-10-10 10:10:10"
注意双引号
重启Linux,时间失效,可以将时间写入BIOS,
hwclock -w
2.使用网络时间,与网络时间同步
查看ntp服务是否启动
service --status-all ###检查ntp服务是否启动
service ntpd status ###如果没安装会提示,
如果没有安装ntp
安装ntp服务命令:
apt-get install ntp 或者 yum install ntp
查看当前时区:date -R
如果是-0500,则不正常,+0800为正常时区
2.1使用tzselect更改时区,选择亚洲 - 中国 - 北京,看英文
修改完成之后可以再次查看时区:date -R,如果还是-0500,请进行最后一步。
复制文件:
cp /usr/share/zoneinfo/Aisa/Shanghai /etc/localtime
可以使用Tab键快速提示
-- end --
附:
如果没有更改成功出现这种情况:
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
vi /etc/profile #编辑文本
在 profile 文件中追加 TZ='Asia/Shanghai'; export TZ
source /etc/profile #使用source命令使其生效
或者直接使用:
echo "TZ='Asia/Shanghai'; export TZ" >> /etc/profile; source /etc/profile
注意: >> 为 追加,> 是覆盖,此处用 >>