OpenWrt Forum Archive

Topic: Setting the timezone

The content of this topic has been archived on 7 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi there

I've just installed the ntp-client package, and now I want to set my timezone so that it shows my date and time correctly. But, I'm a bit stumbled as how to do this.

From the nvram I get the following when searching for something relevant:

time_zone=-08 1 1

But, it's like impossible to figure out what the fields refer to. I'm GMT+1, if that's of any interest.

Ok, I've figured out that the first field is the offset, and basically the interesting part for me.

Searching the firmware gave me the following:

time_zone="+01 2 2"

But, when I run ntpclient I'm still not synchronized according to it:

# date
Fri Jun  4 12:48:58 UTC 2004

When I was using ntpclient, i did the following to set my timezone (also GMT+1):

root@ap:/# export TZ="CET-1CETDST"

I put this also into my /etc/profile to set it at boottime. Otherwise this setting will be lost after a reboot.

But why don't you use rdate?
You don't have to set a timezone and you don't have to install an extra package (rdate is included in openwrt by default).
Here are some rdate Servers (I use the first one):
o 128.138.140.44
o 171.64.7.77
o 171.64.7.99
o 171.64.7.55
To update the time of your unit at every reboot just add this line to your /etc/init.d/rcS:

/usr/sbin/rdate 128.138.140.44

When I was using ntpclient, i did the following to set my timezone (also GMT+1):

root@ap:/# export TZ="CET-1CETDST"

I put this also into my /etc/profile to set it at boottime. Otherwise this setting will be lost after a reboot.

Thanks! That solved it for me.

Damn shame that ntpclient can't run as a daemon, tried ntpclient -c 0 -h <host>, but it just ran once and went down. Maybe add a cron job for that.

But why don't you use rdate? You don't have to set a timezone and you don't have to install an extra package (rdate is included in openwrt by default).

Well, I'm only used to ntp, that's why I went for that. Besides, it looks like you have to set the timezone for rdate to work correctly too.

Damn shame that ntpclient can't run as a daemon, tried ntpclient -c 0 -h <host>, but it just ran once and went down. Maybe add a cron job for that.

Well .. for people like me who reboot their WRT54G every day, there's no need to update the time that often. :mrgreen: I only do this at boottime.

Well, I'm only used to ntp, that's why I went for that.

Me too. Since someone told me how easy rdate really is. smile

Besides, it looks like you have to set the timezone for rdate to work correctly too.

I'm not really sure, but I did not set the timezone after a reboot. I just updated my time via rdate. And although i did not set the timezone, the time was correct.

Well .. for people like me who reboot their WRT54G every day, there's no need to update the time that often. :mrgreen: I only do this at boottime.

# uptime
10:17pm  up 54 days, 22:17, load average: 0.07, 0.01, 0.00

Let's not get all male about uptimes, but I thought that was pretty nice. smile

Me too. Since someone told me how easy rdate really is. smile

Yeah, I'm changing myself now. ntpclient is now uninstalled.

To update the time of your unit at every reboot just add this line to your /etc/init.d/rcS:

/usr/sbin/rdate 128.138.140.44

Hehe, I don't know what's going on, but that is actually not working at all. Sure it doesn't need to be run from a shell or something? I've tried inserting that line into every possible stage of the bootup process (of course after network), but it still doesn't synchronize.

I'm scratching head here.

It works fine here.
Did you follow the steps of the HowTo?
And did you really edit the /etc/init.d/rcS?
And, probably another error may be that you've put this line at the end of the file. I put right after the comments at the beginning of this file.

Hehe, I don't know what's going on, but that is actually not working at all. Sure it doesn't need to be run from a shell or something? I've tried inserting that line into every possible stage of the bootup process (of course after network), but it still doesn't synchronize.

I'm scratching head here.

Is the /usr/sbin/rdate symlink there? smile
Just checking... I've lost a couple of symlinks before.

Other than that, what output do you get if you try to run it through a shell?

Hyggelig å se en nordmann til, forresten tongue

Is the /usr/sbin/rdate symlink there? smile Other than that, what output do you get if you try to run it through a shell?

I have no idea what's going on, but all of a sudden it suddenly started working.

I'm going to put it into a crontab to synchronize it daily, so the bootup isn't that important.

Hyggelig å se en nordmann til, forresten tongue

Hehe, hører med til sjeldenhetene, eller? smile

From the nvram I get the following when searching for something relevant:

time_zone=-08 1 1

But, it's like impossible to figure out what the fields refer to. I'm GMT+1, if that's of any interest.

Extracted from buildroot/build_mipsel/WRT54GS/release/src/router/www/cisco_wrt54g_en/index.asp

"-12 1 0" (GMT-12:00) Kwajalein
"-11 1 0" (GMT-11:00) Midway Island, Samoa
"-10 1 0" (GMT-10:00) Hawaii
"-09 1 1" (GMT-09:00) Alaska
"-08 1 1" (GMT-08:00) Pacific Time (USA & Canada)
"-07 1 0" (GMT-07:00) Arizona
"-07 2 1" (GMT-07:00) Mountain Time (USA & Canada)
"-06 1 0" (GMT-06:00) Mexico
"-06 2 1" (GMT-06:00) Central Time (USA & Canada)
"-05 1 0" (GMT-05:00) Indiana East, Colombia, Panama
"-05 2 1" (GMT-05:00) Eastern Time (USA & Canada)
"-04 1 0" (GMT-04:00) Bolivia, Venezuela
"-04 2 1" (GMT-04:00) Atlantic Time (Canada), Brazil West
"-03.5 1 1" (GMT-03:30) Newfoundland
"-03 1 0" (GMT-03:00) Guyana
"-03 2 1" (GMT-03:00) Brazil East, Greenland
"-02 1 0" (GMT-02:00) Mid-Atlantic
"-01 1 2" (GMT-01:00) Azores
"+00 1 0" (GMT) Gambia, Liberia, Morocco
"+00 2 2" (GMT) England
"+01 1 0" (GMT+01:00) Tunisia
"+01 2 2" (GMT+01:00) France, Germany, Italy
"+02 1 0" (GMT+02:00) South Africa
"+02 2 2" (GMT+02:00) Greece, Ukraine, Romania, Turkey
"+03 1 0" (GMT+03:00) Iraq, Jordan, Kuwait
"+04 1 0" (GMT+04:00) Armenia
"+05 1 0" (GMT+05:00) Pakistan, Russia
"+06 1 0" (GMT+06:00) Bangladesh, Russia
"+07 1 0" (GMT+07:00) Thailand, Russia
"+08 1 0" (GMT+08:00) China, Hong Kong, Australia Western
"+08 2 0" (GMT+08:00) Singapore, Taiwan, Russia
"+09 1 0" (GMT+09:00) Japan, Korea
"+10 1 0" (GMT+10:00) Guam, Russia
"+10 2 4" (GMT+10:00) Australia
"+11 1 0" (GMT+11:00) Solomon Islands
"+12 1 0" (GMT+12:00) Fiji
"+12 2 4" (GMT+12:00) New Zealand

Note : Don't forget to backslash any special characters (like space) when you do you nvram set time_zone=-05 2 1

The nvram variables time_zone is supported by Linksys firmware. Changing this won't make your system globally affected. If you have enabled syslogd, it would not logging with your local time on booting.

To make a "effective" time zone for your OpenWrt, you might be better setting your time zone following uClibc's concept:

http://leaf.sourceforge.net/doc/guide/buci-tz.html

for example:

I would like to have a /etc/TZ with the single line

TAIST-8

which means TAIpei Standard Time 8 hours earlier than UTC.

phil wrote:

When I was using ntpclient, i did the following to set my timezone (also GMT+1):

root@ap:/# export TZ="CET-1CETDST"

I put this also into my /etc/profile to set it at boottime. Otherwise this setting will be lost after a reboot.

If you don't happen to be in the CET-1CETDST TZ, you can probably find your timezone code here:
http://docs.sun.com/source/816-5523-10/appf.htm

Also, time-a.nist.gov and time-b.nist.gov still support rdate.

-Jesse

The discussion might have continued from here.