8

So I understand that the Raspberry PI works some magic with internet servers and whatnot to get its time and that I need to wave some magic dust over the localtime link and possibly /etc/timezoneinfo to get it to work.

The thing is - it seems to be an entire day out and I think that it is configured to the correct time zone. See the following screenshot:

Time Zone

Notice the date in the top right hand corner and compare it with the date in the terminal and with the browser behind showing the date and time. Notice also that I pinged google and it came back fine so it has an internet connection.

I am in central european time so I did all this based on this page:

cd /etc
sudo rm localtime
sudo ln -s /usr/share/zoneinfo/CET localtime
export TZ=CET
sudo vi timezone
CET

And still this weird date thing. So, what gives? How can I get it to have the correct time information?

I tried restarting the ntpd:

/etc/init.d/ntp restart

And checking the peers:

$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 94.136.21.140   73.121.249.250   2 u   27   64    1  1432.35   -7.155 140.072
 ns4.nosuchhost. 131.130.251.107  2 u   30   64    1  1700.38  118.357  18.616
 ntp1.sil.at     183.183.106.246  3 u   37   64    0    0.000    0.000   0.001
 fetchmail.media 83.64.124.251    2 u  20h   64    0    0.000    0.000   0.001

running ntptime gives:

ntp_gettime() returns code 5 (ERROR)
  time d56c8b65.3a5f0000  Wed, Jun 19 2013 21:56:21.228, (.228012),
  maximum error 16000000 us, estimated error 16000000 us, TAI offset 0
ntp_adjtime() returns code 5 (ERROR)
  modes 0x0 (),
  offset 0.000 us, frequency -28.937 ppm, interval 1 s,
  maximum error 16000000 us, estimated error 16000000 us,
  status 0x4041 (PLL,UNSYNC,MODE),
  time constant 7, precision 1.000 us, tolerance 500 ppm,

Still the time is wrong and I see an ERROR! But how do I solve that?

6

ping to google looks just fine, but what results you get from ntptime ?

$ ntptime
ntp_gettime() returns code 0 (OK)
  time d56c8aa0.a60e5194  Thu, Jun 20 2013  4:53:04.648, (.648656024),
  maximum error 817308 us, estimated error 952 us, TAI offset 0
$

also, for changing your time zone, the recommended way is running sudo raspi-config, then using 4 Internationalisation Options and I2 Change Timezone to do the trick instead of manually editing config files.

  • ooh, I get an error - see update to question. Where do I go from here? – kmp Jun 19 '13 at 19:58
  • ah ha - thank you! Using the raspi-config tool and setting it that way has kicked it into life and now I have the correct time :-) – kmp Jun 19 '13 at 20:00
  • 1
    congratulations! =) – lenik Jun 19 '13 at 20:03
2

Only vaguely related, but since the Raspberry Pi doesn't have an RTC it is handy to install chrony which adjusts the clock's rate based on how much it lags or leads the NTP server.

Suppose your clock is 3 minutes slow. Rather than make the system's clock jump forward 3 minutes, chrony will make the clock appear to tick faster than 1 seconds every actual second, and so the system's time will gradually "drift" back to the correct time. This avoids nasty discontinuities in applications, log files, and the like.

sudo apt-get install chrony

And an example showing my Pi's frequency being corrected by 16.671 pulses per minute:

# pi@flux:/home/pi (master)
# chronyc
chrony version 1.24, copyright (C) 1997-2002 Richard P. Curnow
chrony comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
See the GNU General Public License version 2 for details.

chronyc> tracking
Reference ID    : 193.175.73.151 (char-ntp-pool.charite.de)
Stratum         : 3
Ref time (UTC)  : Thu Jun 20 23:37:27 2013
System time     : 0.000000445 seconds fast of NTP time
Frequency       : 0.000 ppm fast
Residual freq   : -16.671 ppm
Skew            : 1000000.000 ppm
Root delay      : 0.032029 seconds
Root dispersion : 18.442499 seconds
chronyc> 

Thought a thread on NTP could benefit from this tip. Sorry it's off-subject.

  • thanks for your contributions! ntpd actually also drifts the time slowly if the difference is too big. – lenik Jun 21 '13 at 13:20
  • That's why you want to set it to query the Stratum-1 NTP server time.nist.gov, as explained here: 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/… – SDsolar Jun 24 '17 at 4:59
2

Restart the NTP daemon

All my configs, timezone, internet connection were ok, the daemon was also running but the time was wrong. So this is how I fixed it.

sudo /etc/init.d/ntp restart

Voila! correct time.

1

You are going to want to make sure your Pi is getting the time from the Master Clock instead of from the pools that are set up by default.

That time server is named time.nist.gov

The best part about using this URL is that it is smart and finds the quickest time server to give you the best results.

Rather than retypee the whole procedure, I'll refer you to a Q&A on this Stack Exchange that shows how easy of a change it is:

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:

How do I set Raspbian to use the primary time server time.nist.gov?

Same thing with Windows computers. They also are set by default to pools, with the same result. The procedure to fix them is included int he same article referenced above.

0

It may be due to the fact that the Raspberry Pi doesnt have an RTC (real time clock). So if you turn off the device, then the next time you turn it on, the time will be wrong. People do make RTC's for the Pi. May not be the best but here is one.

The battery is to provide power to the IC to keep the clock moving you could say.

  • Thanks for the answer but the thing is - if it has power and it is connected to the interent it should just be able to get its time shouldn't it - no reason for anything extra. – kmp Jun 19 '13 at 19:04
  • maybe its a one time set, and the computer (Raspberry Pi) is suppose to keep the time going. I do that a desktop computer acts that way. im pretty sure the Pi or computer isnt going to constantly check and reset the time. you may have to tell the computer (pi) to refresh or update the time. – Alex Jun 19 '13 at 19:20
0

You could possibly also take a look at the command sudo dpkg-reconfigure tzdata as well. That will allow you to change time zones pretty easily. That's what I've used whenever I've seen a time issue.

0

If you have no internet connection, you may want to set the time manually:

sudo date -s "Tue Feb 28 18:02:54 GMT 2017"
-1

Here is a script that you can set to run on boot to fix your time

#######!/bin/bash
#######Visit www.timeapi.org to find the correct url for your timezone. Then replace the url in the first line

time=$(wget http://www.timeapi.org/utc/in+two+hours?format=%25d%20%25b%20%25Y%20%25I:%25M:%25S -q -O -)
echo "Time set to:"
sudo date -s "\`echo $time`"
  • You don't sudo date - that's what ntpd is for. – Frank Kusters Dec 12 '16 at 7:45
  • Welcome to Raspberry Pi SE. Please take the tour at raspberrypi.stackexchange.com/Tour to get the most out of this site. The downvote is mostly due to this being way off base as a useful answer, I'm afraid. You can turn that around with editing it to a more realistic solution or deleting this one entirely. – SDsolar Jun 24 '17 at 5:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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