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
  • 745
  • 5
  • 11
  • 25

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
  • 62,573
  • 32
  • 113
  • 225
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
  • 745
  • 5
  • 11
  • 25
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
  • 18
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
  • 12,005
  • 9
  • 48
  • 77