linux系统修改时间同步时间,修改Linux系统时间,和网络时间同步

1.手动修改(缺点:有偏差)

441caa740538cdc647cad748a3829c06.png

使用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 ###如果没安装会提示,

b82cbf9057b7591860e12857e62604ff.png

如果没有安装ntp

安装ntp服务命令:

apt-get install ntp  或者 yum install ntp

查看当前时区:date -R

b00b4dabe67dea55ac354f52c2411403.png

如果是-0500,则不正常,+0800为正常时区

2.1使用tzselect更改时区,选择亚洲 – 中国 – 北京,看英文

ee62d5857928e1e49f017e615173469f.png

修改完成之后可以再次查看时区: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

注意: >> 为 追加,> 是覆盖,此处用 >>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值