WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Date, time, timezone  (Read 11965 times)

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Date, time, timezone
« on: July 28, 2014, 08:09:05 PM »
Been having fun getting date, time, time zones sorted out for IoT RPi's

The IoT RPi temperature loggers read and log i2c temperature sensors with python code + python-smbus lib.
They are on a 10.x.x.x device network behind a firewall.

bootsync.sh calls my run.sh script after sleep of 60 secs for network to do it's stuff.

run.sh contains line - sudo ntpdate "local timeserver"
This updates time/date on power up from our local time server.
Tried ntpd -q etc but it does not work as well as ntpdate x.x.x.x
Now date is 2014 etc and not 1970 etc.
But timezone was wrong.

Tried the boot command.txt,  tz=GMT+10 (Australia/Brisbane) but it subtracted 10hrs from the network time.
Everything worked when bootcode was tz=GMT-10
date now reports correct local time except it says GMT, not GMT+10

Tried noutc , tz=UTC+10, tz=Australia/Brisbane (tzdata.tcz needed?) and other combinations.
Not sure exactly where I should be setting tz info.




Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: Date, time, timezone
« Reply #1 on: July 28, 2014, 09:46:55 PM »
You've the unix people to thank for the "GMT-10" - for some reason they decided to count in a direction contrary to logic. "GMT-10" is correct.

Note that you only need "noutc" if your bios clock is set to local time (the windows way) - if it is set to GMT/UTC (the linux/unix way) then there is no need for this boot code.

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 402
Re: Date, time, timezone
« Reply #2 on: July 29, 2014, 05:30:12 AM »
hi gavinmc42,

I spent days fiddling with this also.

Here's what I do.

1. Get timezone string from here: http://wiki.openwrt.org/doc/uci/system#time.zones
2. Set $TIMEZONE equal to tz string
3. echo "TZ="$TIMEZONE > /etc/sysconfig/timezone
4. echo "etc/sysconfig/timezone" >> /opt/.filetool.lst
5. backup or sudo filetool.sh -b
6. reboot

Seems to works well for Sydney TZ=EST-10EST,M10.1.0,M4.1.0/3.

regards

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Date, time, timezone
« Reply #3 on: July 31, 2014, 06:50:03 PM »
Ah, a Unix bug/feature, probably seemed logical at the time, or maybe just a typo nobody fixed.

Changing  to TZ=EST-10 seems to work, no daylight saving here.

Now TC date returns the same time as Raspbian :)

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Date, time, timezone
« Reply #4 on: August 13, 2014, 07:49:05 PM »
Been testing for a week now on the Uni network.

A script that calls ntpdate "timeserver address" is needed when RPi first boots.
ntp then keeps it all synced to the time server.

Now all I need is to make a time server for my home RPi network.
Going to need a RPi with a battery backed RTC and some server program.

Anyone know what service serves the time?

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 402
Re: Date, time, timezone
« Reply #5 on: August 13, 2014, 08:48:03 PM »
hi gavinmc42,

Are you sure you need to do this?

My Raspberry Pi (with piCorePlayer) seems to already set the time properly.

Have a look at:

/etc/init.d/tc-config
/etc/init.d/settime.sh
/usr/bin/getTime.sh
/etc/sysconfig/ntpserver

Maybe dependant on DHCP running????

regards

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Date, time, timezone
« Reply #6 on: August 13, 2014, 09:02:05 PM »
yep need DHCP and NTP time servers etc.

Ok, if you have internet connection, not when run local only networks.

So want to fake up a RPi with RTC as a DHCP/time server.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Date, time, timezone
« Reply #7 on: August 14, 2014, 01:34:36 AM »
/etc/sysconfig/ntpserver file defines the ntp server used. Edit if you need a different server, add file to your backup and make a backup.

During startup system executes getTime.sh to get time. You can execute it manually any time later. Please note, system time may be updated few seconds after script executed.

BusyBox ntp daemon is part of base, you can use it to keep system time occurate without installing anyting from the repo.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

paco

  • Guest
Re: Date, time, timezone
« Reply #8 on: October 03, 2014, 09:32:49 AM »
Old thread, but these are my experiences:

Timezones:
  • I installed tzdata.tcz and use tz=Europe/Berlin in cmdline.txt. Works fine for me.
  • Using /etc/localtime instead of tz-Parameter in cmdline.txt does not work.
  • Nice overview about timezone-formats: http://stackoverflow.com/tags/timezone/info


ntp-client:

getTime.sh is executed only once at boottime. As -q is used, setting the time without network connection does not work.

I prefer using ntp as a daemon, giving a high long-term accuracy. The ntp-client itself calculates how often a network service must be polled.

Cheers,
Patrick

Offline eSPee

  • Newbie
  • *
  • Posts: 13
Re: Date, time, timezone
« Reply #9 on: April 29, 2022, 06:35:54 AM »
Dear all,

i am running piCore 9.x on a ZeroW. Managed to set the time by adding "export TZ= TZ=CET-1CEST,M3.5.0,M10.5.0/3
" = Europe/Amsterdam to the home/tc .profile file and installed TZdata.tcz (11.x-x86_64 version). The "date" function now shows the correct time ;)

However i also have some cronjobs running, but they don't execute on the correct time, but 2 hours in advance   :o

To correct this i also added the TZ= code to cmdline.txt and cmdline3.txt, nevertheless this didn't help.
Could it be that the crontabs run by a different time then tc? How can i correct this?

Thnx in advance ;)

Offline eSPee

  • Newbie
  • *
  • Posts: 13
Re: Date, time, timezone
« Reply #10 on: April 29, 2022, 08:42:32 AM »
Solved it ;)

I needed to set the localtime as well with a symbolic link:

 sudo ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime

;)