1

I work at a manufacturing plant and we use raspberry pis for videos on a schedule. We use Screenly to schedule when certain videos will play back but currently I also need to manually correct the date and time.

I do have a script that we run whenever we are configuring a new raspberry pi that take care of a lot of things for us like changing the pi user password, enabling ssh, changing the hostname etc. I would like for this on boarding script to also handle correcting the date and time. So far I have gotten the timezone to be corrected but the time is still an hour off and the date is WAY OFF. I am configuring a rpi today and the date says april 27, 2019. As a part of the script I am installing ntpdate (a solution I found online) but it does not seem to be working.

Does anyone know how I could do this? I know we could use raspi-config but I want us to only to have to run this script and everything else is taken care of.

  • Without seeing your script we can’t know what you did wrong – Milliways Jul 11 at 22:39
  • @Chad, you can use the python module "datetime" to sync to Network time. You might like to read my little program for more details - penzu.com/public/8e883ae5 – tlfong01 Jul 12 at 0:48
1

Raspbian has a service that updates the date and time automatically, but your raspberry has to have internet connection. As the raspberry doesn't have an external/power independent clock, every time you turn off your raspberry, it will record the actual date time. When turned on, it will assume that the date and time is the last recorded, but it will not consider the time it was off, so even a reboot will add some delay. If the raspberry doesn't have access to internet, it will never have the right date and time.

About your init script, you can config the timezone via command line changing the /etc/localtime file. For example, if you want to set Japan timezone:

sudo cp /usr/share/zoneinfo/Japan /etc/localtime

At /usr/share/zoneinfo you will find all the options of timezone (some are folders and others are the file you want to copy):

pi@raspberrypi:/usr/share/zoneinfo $ ls
Africa      CET      Etc      Greenwich    Japan              Navajo      PST8PDT    US
America     Chile    Europe   Hongkong     Kwajalein          NZ          right      UTC
Antarctica  CST6CDT  Factory  HST          leap-seconds.list  NZ-CHAT     ROC        WET
Arctic      Cuba     GB       Iceland      Libya              Pacific     ROK        W-SU
Asia        EET      GB-Eire  Indian       localtime          Poland      Singapore  zone1970.tab
Atlantic    Egypt    GMT      Iran         MET                Portugal    SystemV    zone.tab
Australia   Eire     GMT+0    iso3166.tab  Mexico             posix       Turkey     Zulu
Brazil      EST      GMT-0    Israel       MST                posixrules  UCT
Canada      EST5EDT  GMT0     Jamaica      MST7MDT            PRC         Universal

You also can set manually the date and time of your raspberry using date --set. For example:

sudo date --set "2019-07-11 12:00:00"

Hope it helps you!

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.