树莓派时间校正

树莓派时间校正

hash070 418 2022-02-02

树莓派没有电池,断电后无法保存时间,树莓派默认安装了NTP(Network Time Protocol)服务来获取互联网上ntp服务器提供的时间。如果由于系统或网络原因导致该服务出错,就会导致树莓派出现时间错误。本篇文章的主要目的是为了记录如何解决树莓派无法自动校正时间的问题。

树莓派时间校准命令

#首先使用ntpdate校准时间
ntpdate ntp.aliyun.com
sudo ntpd -s -d

树莓派时间设置命令

sudo date  --s="2022-08-31 14:42:00"

如果时间校正失败,可以尝试配置国内可用的ntp服务器

修改ntp服务配置文件

sudo nano /etc/ntp.conf

在这两行下添加自定义的ntp服务器

# You do need to talk to an NTP server or two (or three). 
# server ntp.your-provider.example

常用的ntp服务器

server ntp.fudan.edu.cn iburst perfer 
server time.asia.apple.com iburst 
server asia.pool.ntp.org iburst 
server ntp.nict.jp iburst 
server time.nist.gov iburst 

修改完成后推出编辑,然后重启ntp服务

sudo /etc/init.d/ntp restart