I know that Raspberry Pi does not come with a system clock to save money. How can I keep system time though?
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)
ntpdate is deprecated: support.ntp.org/bin/view/Dev/DeprecatingNtpdate Aug 12, 2012 at 15:23
1/etc/rc.conf is also deprecated.– rubenvbFeb 8, 2013 at 22:32
1if /etc/rc.conf is deprecated, what's the alternative? This is exactly what I need. Apr 1, 2013 at 14:17
systemctl enable ntpd.serviceis similar to adding to
/etc/rc.conf. May 10, 2013 at 13:34
Fresh installs have it pick up time from a variety of sources that can be many hops from the Master clock. For details, and for the reason why you should change it to time.nist.gov, see this Q&A: raspberrypi.stackexchange.com/questions/68811/…– SDsolarJun 24, 2017 at 4:50
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
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
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.
1For interest, the MSF time signal is actually now broadcast from Anthorn Radio Station in Cumbria, not Rugby. Nov 13, 2012 at 16:18
1Not 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)– winwaedNov 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. 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!– winwaedNov 14, 2012 at 14:03
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.