linux日期同步和时间类

date 显示当前的时间
基本语法

1) date  (功能描述:显示当前时间)
2) date +%Y  (功能描述:显示当前年份)
3) date +%m  (功能描述:显示当前月份)
4) date +%d  (功能描述:显示当前是哪一天)
5) date "+%Y-%m-%d %H:%M:%S"(功能描述:使用特定格式显示年月日时分秒)

手动设置系统时间如下
date -s “字符串时间” 例如:

 date -s "2020-11-11 11:22:22"

cal 查看日历
在这里插入图片描述查看指定年份日历
在这里插入图片描述

时间同步
经常使用 Linux 的同学都知道 Linux 的时间默认无法和 internet 同步,所以需要进行如下操作:

  1. 执行 yum install ntpdate 下载 Linux 时间同步服务软件 (这里已经下载)
    在这里插入图片描述注:如果你用的是centos7.0以下的版本,从2020年 12 月 2日,网易,阿里,清华等镜像不在提供更新维护,也就是不能用。换或者看另一篇博文
    https://blog.csdn.net/qq_43674360/article/details/111300657
    设置当前时间
    在这里插入图片描述 系统硬件时间同步
    在这里插入图片描述设置时间同步的定时任务
    因为需要 root 权限,所以建议使用 root 用户登陆并执行以下命令:
    查看开机是否启用
    执行crontab -e
    在这里插入图片描述
    * */1 * * * ntpdate ntp.api.bz; hwclock -w (每小时同步虚拟机时间和硬件时间)

在这里插入图片描述重启crond
在这里插入图片描述
ok

附:
如果上面ntpdate ntp.api.bz服务器同步不了,可以换下面几个时间服务器试一下:
0.# ntpdate time.nist.gov
1.# ntpdate time.nuri.net
2.# ntpdate asia.pool.ntp.org
3.# ntpdate ntp.api.bz
希望可以帮到你!!!

猜你喜欢

转载自blog.csdn.net/qq_43674360/article/details/111308378