修改校准debain/manjaro的时间时钟

一次重启后发现时间竟然从上午变成了晚上!要问,我是怎么发现在的我就是发现上午的时候我的屏幕夜灯突然出现了

使用命令

sudo rm -f /etc/localtime删除本地时间文件

sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime复制时区文件到localtime。

sudo apt install ntpdate”安装“ntpdate”

sudo ntpdate -u ntp.api.bz”将本地时间与网络时间同步

sudo date查看当前系统时间是否更新

sudo hwclock -w”保存配置

这时候应该就没有时间问题了

原因:可能是强制关机引起的

manjaro的修改方法

date  --set=字符串           将时间设置为 <字符串> 所描述的时间

例如:sudo date  --set "2022-11-10 10:10:10"

sudo hwclock -w”保存配置

或者使用脚本:

echo "|-检查ntpdate命令是否就绪.."
is_ntpdate=$(which ntpdate)
if [ "$is_ntpdate" = "" ];then
   if [ -f /usr/bin/apt ];then
       apt install ntpdate -y
   else
       is_dnf=$(which dnf)
       if [ "$is_dnf" = "" ];then
                yum install ntpdate -y
       fi
   fi
fi
is_ntpdate=$(which ntpdate)
is_http=0
if [ "$is_ntpdate" != "" ];then
    echo "|-正在尝试从1.pool.bt.cn同步时间..";
    ntpdate -u 1.pool.bt.cn
    if [ $? = 1 ];then
       echo "|-正在尝试从0.asia.pool.ntp.org同步时间..";
       ntpdate -u 0.asia.pool.ntp.org
   fi
else
    is_http=1
fi
if [ $? = 1 ] || [ $is_http = 1 ];then
    echo "|-正在尝试从www.bt.cn同步时间..";
    getBtTime=$(curl -sS --connect-timeout 3 -m 60 http://www.bt.cn/api/index/get_time)
    if [ "${getBtTime}" ];then
        echo "|-设置时间: "$(date -s "$(date -d @$getBtTime +"%Y-%m-%d %H:%M:%S")")
    fi
fi
echo "|-正在尝试将当前系统时间写入硬件..";
hwclock -w
echo "|-当前时间为:$(date)"
echo "|-时间同步完成!";

这段脚本实在宝塔面板上搞下来的!

posted @ 2022-11-02 10:51  Teot  阅读(626)  评论(2编辑  收藏  举报