Linux 修改系统时间

一. date 查询当前时间

[root@localhost ~]# date -R  
Sat, 01 Jan 2000 12:02:12 -0400

        后面的那个 -0400 表示时区,需要用 tzselect 进行设置。

 

二. tzselect 设置时区

        输入命令 tzselect 之后,会有 主时区 和 次时区 的选择,选择完毕其实没有设置成功,会出现如下界面:

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

        然后在 /etc/profile文件末尾加上这行: TZ='Asia/Shanghai'; export TZ 。保存文件后,用 source 执行一次。如下:

vi /etc/profile                          // 打开文件
TZ='Asia/Shanghai'; export TZ            // 添加行
:wq                                      // 保存退出
source /etc/profile                      // 执行 profile

        然后设置软链接:

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

       重新登陆新的 session,调用 date 命令查看时区是否修改成功 (上海是东 8 区):

[root@localhost ~]# date -R
Sun, 02 Jan 2000 01:24:02 +0800


三、hwclock 修改硬件时间

      Linux系统时钟有两个,一个是硬件时钟,即 BIOS 时间;另一个是系统时钟,是 Linux 系统 Kernel 时间。当 Linux 启动时,系统 Kernel 会去读取硬件时钟的设置,然后系统时钟就会独立于硬件运作。有时我们会发现系统时钟和硬件时钟不一致,因此需要执行时间同步,这时候就需要对系统时间进行同步。 
     利用 hwclock 修改硬件时间,然后再同步到系统时间。

[root@localhost ~]# hwclock --set --date="2019/01/04 12:14:00"
[root@localhost ~]# hwclock --hctosys
[root@localhost ~]# date -R
Fri, 04 Jan 2019 12:15:22 +0800

 

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

英雄哪里出来

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值