You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The RTC ensures the Pi has accurate datetime regardless of Internet connection and power loss. To stay up to date, the RTC also needs to be updated whenever the Pi has correct time via network time protocol (NTP) syncing.
4
+
5
+
The instructions below configure the OS for the following behavior:
6
+
- If Pi is disconnected from internet at startup: Update system time from RTC
7
+
- If Pi successfully syncs to NTP via internet: Update RTC from system (NTP) time
8
+
9
+
## Setup instructions
10
+
11
+
The following files need to live in the Pi's `/etc/` directory:
12
+
-`rc.local` sets behavior on boot
13
+
-`dhcpcd.exit-hook` sets behavior on Internet connection
14
+
15
+
Ensure both files have executable permission:
16
+
```
17
+
sudo chmod +x rc.local
18
+
sudo chmod +x dhcpcd.exit-hook
19
+
```
20
+
21
+
## Tests (optional)
22
+
23
+
Reboot after adding the above files to start the RTC before testing.
24
+
25
+
### RTC in use
26
+
27
+
Verify system vs RTC time using `timedatectl` in terminal. You will see a printout like this:
28
+
```
29
+
Local time: Mon 2025-08-25 15:42:07 PDT
30
+
Universal time: Mon 2025-08-25 22:42:07 UTC
31
+
RTC time: Mon 2025-08-25 22:42:08
32
+
Time zone: America/Los_Angeles (PDT, -0700)
33
+
System clock synchronized: yes
34
+
NTP service: active
35
+
RTC in local TZ: no
36
+
```
37
+
38
+
If the RTC did not successfully start, RTC time will be listed as `n/a`.
39
+
40
+
### System updated by RTC
41
+
42
+
Test the use case where there's no Internet connection:
43
+
44
+
First, turn off NTP sync, otherwise the time will automatically be corrected when `timedatectl` is run.
45
+
```
46
+
timedatectl set-ntp false
47
+
```
48
+
49
+
Then, manually write an incorrect date/time to the RTC.
50
+
```
51
+
sudo hwclock --set --date "01/01/2001 00:00:00"
52
+
```
53
+
54
+
Run `timedatectl` to verify the RTC's datetime.
55
+
56
+
57
+
Turn wifi off and reboot. The system time should now be the incorrect RTC time. Be patient as it can take up to 1 min for the system time to update after reconnection.
58
+
59
+
_NOTE: If you ever want to overwrite system time using the RTC on the spot, run `sudo hwclock -s`._
60
+
61
+
### RTC updated bt system (NTP) time
62
+
63
+
Test the use case where the Pi reconnects to Internet:
64
+
65
+
Turn on wifi when it was previously off or reboot Pi. Both the system time and RTC time should be correct and can be verified by running `timedatectl`
66
+
67
+
_NOTE: If you ever want to overwrite the RTC using the NTP time on the spot, run `sudo hwclock -w`._
0 commit comments