9

The electricity to my apartment went out a few days ago.

I use my RPi to record data and store it in a database. I've just learned that the time for all my data has been off by an hour because the RPi's clock is off by an hour.

From here I issued tz select and set it to America/Los_Angeles and it is still one hour slow.

How can I adjust this?

Matthew Moisen
  • 725
  • 5
  • 11
  • 24
  • 1
    Is the clock wrong or is it just the "show to humans" part that is wrong? Show the full output from `date` and what you expected it to be. – Thorbjørn Ravn Andersen Sep 23 '13 at 06:02
  • This Q&A shows what happens during power-outs: https://raspberrypi.stackexchange.com/questions/1397/how-accurate-is-raspberry-pis-timekeeping – SDsolar Jun 20 '18 at 01:32

4 Answers4

9

Sounds like a daylight saving problem.

Use raspi-config see:- http://elinux.org/RPi_raspi-config#change_timezone_-_Set_timezone

You can reset the time

sudo dpkg-reconfigure tzdata
Milliways
  • 54,718
  • 26
  • 92
  • 182
  • Hey Milliways, I have tried raspi-config and `sudo dpgk-reconfigure tzdata`, but there is nothing regarding daylight savings. Am I not seeing it? – Matthew Moisen Sep 22 '13 at 02:06
  • If you have locale and timezone correctly set Linux normally does a good job of managing DST (not like Windows). File times are recorded in UTC and converted to local for dispay.There can still be issues when governments fiddle with DST. `zdump -v Australia/Sydney|grep 2013` shows when times change in my home. You should check what your system says for your zone. – Milliways Sep 22 '13 at 10:02
1

The following worked for me:

sudo reboot

...

I assume that because the RPi gets the time when it is connected to the internet, my RPi booted up faster than my router, and something screwy happened.

After rebooting, the RPi is back on track.

Now I'm off to cleanse some data ...

Matthew Moisen
  • 725
  • 5
  • 11
  • 24
  • 2
    Somewhat confused how this can be the accepted answer. Just because it works for you doesn't mean it works for others. – geotheory Apr 04 '14 at 10:53
  • @geotheory I tried the other answers and they didn't work for me. I found this suggestion on another site, tried it, and all was well. – Matthew Moisen Apr 05 '14 at 01:20
  • So someone else with this problem is going to find the 'accepted' answer to 'How to adjust for Daylight Savings problems?' to reboot. SO is intended to have legacy value. Its not just a helpline. – geotheory Apr 05 '14 at 08:01
  • @geotheory Alright, I see your point and unanswered my answer. However, do I just leave this post unanswered? I don't wish to award the answer to the one with the most upvotes, as that didn't solve the problem for me (whereas rebooting did). – Matthew Moisen Apr 05 '14 at 11:13
  • I'd suggest the solution by @Milliways, which seems to have worked for 4 upvoters (including myself) probably deserves the credit as it is a standard way to change the pi's time zone setting. – geotheory Apr 05 '14 at 12:19
  • To me, this seems like an acceptable answer: it correctly solved the problem described in the question. Others in the same circumstances might well find it solves theirs too. The other answers solve different problems and therefore aren't a solution to this one. The legacy value of SO emerges from the comprehensive, collected body of help that has been provided. There's nothing wrong with making the advice as general as possible for future readers, but if all the asked questions had accepted answers that solved different problems it would be harder to get good info from that body of data. – Bob Sammers Mar 28 '17 at 12:14
0

Sorry to drudge up an old question; however, I recently encountered a similar problem and the various answers here suggested that we need some clarification.

I was able to reproduce the OP's problem by disconnecting power to both my router and RPi, then starting the RPi prior to the router. Under these conditions, the NTP service did not have internet access and apparently relies on the hardware clock. tzdata was correct at the time of the problem.

enter image description here

Rebooting the RPi once the internet connection was restored solved the problem. If for some reason the RPi cannot or should not be shut down, one can restart the NTP service with sudo service ntp restart.

bobthechemist
  • 546
  • 1
  • 6
  • 16
  • Just to be clear :) the Pi doesn't have a hardware clock, although add-on boards are available to provide one. Raspbian includes the `fake-hwclock` package by default which, if network time is not available for some reason, restarts the clock from the time at which the machine was shut down (or some time before then in the event of power failure) at boot. – Bob Sammers Mar 28 '17 at 11:47
0

It's best to store the UTC time in your database and change to localtime only for display purposes.

The main problem with storing local time is that you will get a duplicate hour when daylight saving starts, and skip an hour when daylight saving ends.

Also if you ever have users accessing from different timezones (unlikely for your particular application), it's more difficult to work out the time in the other timezone and impossible to disambiguate that hour at the start of the daylight savings.

John La Rooy
  • 11,847
  • 9
  • 46
  • 74