Paramétrer la date et l'heure
Modifier la date et l'heure manuellement
Connaître la date et l'heure actuelle
pi@raspberrypi:~ $ timedatectl Local time: mar. 2021-06-15 14:26:49 CEST Universal time: mar. 2021-06-15 12:26:49 UTC RTC time: n/a Time zone: Europe/Paris (CEST, +0200) System clock synchronized: no NTP service: inactive RTC in local TZ: no
Modifier
pi@raspberrypi:~ $ sudo timedatectl set-time '2021-06-20 11:06:00'
Résultat :
pi@raspberrypi:~ $ timedatectl Local time: dim. 2021-06-20 11:06:01 CEST Universal time: dim. 2021-06-20 09:06:01 UTC RTC time: n/a Time zone: Europe/Paris (CEST, +0200) System clock synchronized: no NTP service: inactive RTC in local TZ: no
Remarque : pour pouvoir modifier la date et l'heure, il faut que la synchonisation à un serveur NTP ne soit pas activée. Si besoin, il faut la désactiver avec :
pi@raspberrypi:~ $ sudo timedatectl set-ntp false
Synchroniser la date et l'heure avec un serveur de temps
Configurer l'adresse IP du serveur de temps
Il faut modifier la valeur de l'attribut NTP
présent dans le fichier /etc/systemd/timesyncd.conf
à l'aide d'un éditeur comme nano
.
Par exemple si vous utilisez le serveur NTP
d'adresse ntp.obspm.fr
(serveur de temps de l'observatoire de Paris), le résultat de la modification est :
pi@raspberrypi:~ $ sudo cat /etc/systemd/timesyncd.conf [Time] NTP=ntp.obspm.fr #NTP= #FallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org #RootDistanceMaxSec=5 #PollIntervalMinSec=32 #PollIntervalMaxSec=2048
Activer la synchronisation avec le serveur NTP
pi@raspberrypi:~ $ sudo timedatectl set-ntp true
Redémarrer le service systemd-timesyncd
pi@raspberrypi:~ $ sudo systemctl restart systemd-timesyncd
Visualiser le résultat
Visualiser si la synchronisation a été effectuée
pi@raspberrypi:~ $ sudo journalctl -xe | grep Synchronized pi@raspberrypi:~ $ sudo journalctl -xe | grep Synchronized ... raspberrypi systemd[1]: Reached target System Time Synchronized. ... raspberrypi systemd-timesyncd[1030]: Synchronized to time server for the first time 145.238.203.10:123 (ntp.obspm.fr).
Visualiser la date et l'heure
pi@raspberrypi:~ $ timedatectl Local time: Mon 2021-08-23 10:22:35 CEST Universal time: Mon 2021-08-23 08:22:35 UTC RTC time: n/a Time zone: Europe/Paris (CEST, +0200) System clock synchronized: yes NTP service: active RTC in local TZ: no RTC in local TZ: no
Remarque : lors d'un redémarrage, la synchronisation peut prendre quelques minutes :
pi@raspberrypi:~ $ systemctl status systemd-timesyncd ... juin 15 14:02:09 raspberrypi.mazone.lan systemd-timesyncd[310]: Timed out waiting for reply from 172.16.0.2:123 (172.16.0.2). juin 15 14:13:26 raspberrypi.mazone.lan systemd-timesyncd[310]: Synchronized to time server for the first time 172.16.0.2:123 (172.16.0.2).