1

Is their a way of keeping track of the raspberry pi system date and time up to date with the current date and time without connecting to the ethernet? (Raspberry pi 2)

3

4 Answers 4

3

Yes, there is RTC (Real Time Clock) for this. It's a chip with hardware clock onboard, supported by battery power (it acts as independent power source, just for the clock).

See the tutorial showing how to use module with DS1307 chip: https://thepihut.com/blogs/raspberry-pi-tutorials/17209332-adding-a-real-time-clock-to-your-raspberry-pi

1
  • 1
    The instructions in the link you posted pre-date Jessie. You should use Device Tree to setup.
    – Milliways
    Sep 13, 2016 at 6:47
3

The Pi will keep the time it was shutdown and restore on restart. It will thus gradually get out of date.

If you don't want to connect to the internet you will need a RTC. I recommend the DS3231 as it runs on 3.3V and has software support on the Pi, although the DS1307 is very similar but runs on 5V, and is not quite as accurate.

It is also possible to set the time from another computer, connected via Ethernet. If you are interested I will post one method of doing this.

1
1

The pi has no inbuilt real time clock (RTC), when booted it has to guess the time, on the first boot it will default to epoch (the beginning of time for computers), specifically January 1, 1970. Current distros also save the time on shutdown, and restore it on start up which means most of the time you will get the last date/time the pi was running. The pi also uses the cpu clocks which are not accurate for tracking time over a long period of time without slowly drifting and without an RTC it has no way of tracking time while powered down.

You can get external RTC modules that are battery backed, these give the advantage of being able to count time while the pi is powered down (so long as the battery is not dead) as well as being more accurate resulting in a smaller clock drift.

However all clocks slowly drift (this could take years to be of concern). The network time protocol (NTP) was created to correct this. What it does is syncs the time with other NTP servers (some of which as backed by atomic clocks, making them very accurate). A constant connection to an NTP server is not required, as the cpu can count time while it is not connected, but when it is time will slowly sync up with the NTP servers. This does require an internet connection, either by ethernet or wifi. If ethernet is out of the question (even occasionally) then you can use wifi instead. If no network is available at all then you have to rely on the internal clock or external RTC to track time and adjust it occasionally (like you would adjust a watch).

0

I can say I am not fully understand your question but I had similar situation in which I wanted to get track of raspberry uptime without remote connection. so simply I had used this script

#!/bin/bash

cd ~/Scripts/running_time

export start_time=$(date +'%Y/%m/%d___%H:%M:%S') 
printf $start_time > up_time

while true
do

printf 'start time %s \n end at %s' $start_time, $(date +'%Y/%m/%d___%H:%M:%S') > up_time
sleep 1

done

where "~/Scripts/running_time" is just text file to print the uptime every second

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.