45

I know that Raspberry Pi does not come with a system clock to save money. How can I keep system time though?

5 Answers 5

42

Software Solution

The most popular method of keeping system time is via the Network Time Protocol daemon (NTPd).

NTPd is the most common method to synchronize the software clock of a GNU/Linux system with internet time servers using the Network Time Protocol.

NTPd should already be installed and set up on the default operating system, Debian Squeeze. You will need to install and configure it manually though for Arch Linux.

First you should install NTP.

$ sudo pacman -S ntp

Now you can manually update it via the command line.

$ sudo ntpd -qg

Or you can add it to the list of daemons on start up by adding it to your /etc/rc.conf file. Like so.

# /etc/rc.conf
DAEMONS=(!hwclock ntpd)

Note that you need to disable hwclock by preceding it with an exclamation mark (!) in the daemons list.


Protip from mlp: If you add ntpdate to your list of daemons the time will be corrected after boot much faster. So your daemons list would look like so.

# /etc/rc.conf
DAEMONS=(!hwclock ntpd ntpdate)
5
16

Hardware Solution

If you want to guarantee that the time on the RPi is always correct or want to maintain the time without a network connection, you will need to buy an expansion board with a Real Time Clock (RTC) on it: there is at least one available and at least one in development.

Available RTC Expansion Boards

RTC Expansion Boards in Development

4

Install the NTP daemon on Arch Linux with systemd:

sudo pacman -S ntp
sudo systemctl enable ntpd
sudo systemctl start ntpd

Also make sure your timezone is set correctly, in my case:

sudo rm /etc/localtime
sudo ln -s  /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
2
  • This is the proper way to do it on systems that use systemd init.
    – 71GA
    Feb 18, 2021 at 9:13
  • On Raspbian it is ntp.service and not ntpd.service.
    – 71GA
    Feb 18, 2021 at 11:08
3

For non-networked applications (or where network time might not be good enough), you can set your RTC clock (@Alex Chamberlain's answer) with time derived from a GPS receiver or a VLF receiver (in NW Europe this would be Rugby MSF). Both could be excellent solutions to field-deployed devices (robots, field monitoring, etc).

Both solutions would also make good hobby projects. I remember building a Rugby MSF receiver in the 1980s. An off the shelf GPS receiver ("puck") would give the time and date in the NMEA 0183 sentences - it would then be a simple coding project to extract this information.

4
  • 1
    For interest, the MSF time signal is actually now broadcast from Anthorn Radio Station in Cumbria, not Rugby.
    – tomfanning
    Nov 13, 2012 at 16:18
  • 1
    Not living in the UK at the moment, I haven't driven down the M1 for a while: So have they taken down the 'forest'? (I assume the nearby naval masts at Daventry are still there)
    – winwaed
    Nov 13, 2012 at 16:38
  • Not sure - I'm on the wrong side of the country for the M1. However, Rugby Radio Station appears to have stopped being active in mid 2007 according to en.wikipedia.org/wiki/Rugby_Radio_Station - with references to demolition, including a photo. And there's a video here: youtube.com/watch?v=bx2lhSUuGqU. However, there are masts still visible on Google Street View, which I'm fairly sure is newer imagery than 2007.
    – tomfanning
    Nov 14, 2012 at 13:07
  • And looking around on Wikipedia, there's no mention of "naval" masts at Daventry so I must be mistaken - just a very old (now dismantled) transmitter to the Empire. So now the M1 drive is even more boring!
    – winwaed
    Nov 14, 2012 at 14:03
0

If you don't want to have NTP running on your system the whole time you can use one of a few different options to set the time:

  • ntpdate - Once installed it sets the system up to obtain the time when any interface comes up (although 'deprecated' it's still fairly widely used).
  • rdate - Simpler and lighter weight approach, though a bit less accurate.
  • tlsdate - A more secure option which uses an TLS/SSL server as a time source.

Obviously your clock wont be as accurate as using NTP since all clocks do drift, and also since these apps only use a single time source they can potentially result in setting the incorrect time if their chosen source has a problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.