linux date synchronization and time class

date displays the current time
basic syntax

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

Manually set the system time as follows
date -s "string time" For example:

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

cal View the calendar View the calendar of the
Insert picture description herespecified year
Insert picture description here

Time synchronization
Students who often use Linux know that Linux time cannot be synchronized with the internet by default, so you need to perform the following operations:

  1. Execute yum install ntpdate to download the Linux time synchronization service software (downloaded here)
    Insert picture description hereNote: If you are using a version below centos7.0, from December 2, 2020, Netease, Ali, Tsinghua and other mirrors will not provide update maintenance. It just can't be used. Change or read another blog post
    https://blog.csdn.net/qq_43674360/article/details/111300657
    Set the current time
    Insert picture description hereSystem hardware time synchronization
    Insert picture description hereSet the timing task of time synchronization
    because root privileges are required, so it is recommended to log in and execute as root user The following command:
    Check whether the boot is enabled,
    execute crontab -e
    Insert picture description here
    * */1 * * * ntpdate ntp.api.bz; hwclock -w(synchronize the virtual machine time and hardware time every hour)

Insert picture description hereRestart crond
Insert picture description here
ok

Attachment:
If the above ntpdate ntp.api.bz server cannot be synchronized, you can try the following time servers:
0.# ntpdate time.nist.gov
1.# ntpdate time.nuri.net
2.# ntpdate asia.pool. ntp.org
3.# ntpdate ntp.api.bz
hope to help you! ! !

Guess you like

Origin blog.csdn.net/qq_43674360/article/details/111308378