Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I find which time-zone is currently in effect on my system and get offset to it?

I need this information in order to offset some time calculations and I cannot make it constant because of daylight saving time (which effectively changes offset).

E.g. Currently my time-zone offset is +02:00 and it will be +01:00 during winter. I need to get which one it is and offset in hours (e.g. in this case answer should be 2).

I would need to do this in either tcsh or bash.

From command line it looks like time-zone isn't set (date "+%z" returns 0). However, from web interface time-zone is set to Europe/Zagreb. I would like to get offset to that time-zone.

Version of FreeNAS is 0.7 RC1.

share|improve this question
up vote 5 down vote accepted
$ date "+%Z"

Will give you the current timezone

$ date "+%z"

Will give the offset from DST

share|improve this answer
I tried this already but both of them give me 0. – Josip Medved Aug 21 '09 at 5:33
It seems that FreeNAS just removed bunch of stuff in order to save on size. However, what made me look on wrong side is that web interface does allow time-zone to be set to Europe/Zagreb. That setting is never "flushed" to file system. – Josip Medved Aug 21 '09 at 5:37
Dang :( No idea, then. How about "echo $TZ" in a terminal? – Bill Weiss Aug 21 '09 at 14:28
I suppose "no idea" isn't correct, since I followed that with an idea. – Bill Weiss Aug 21 '09 at 14:29

FreeNAS runs on FreeBSD, so using as a guide:

FreeBSD Setup Timezone

To setup corrct timezone you need to copy your timezone file from /usr/share/zoneinfo directory to /etc/localtime file. Just goto directory:

# cd /usr/share/zoneinfo

Use ls -l command to find out your zonefile.

# ls -l

For example I am in Asia/Culcatta (IST time zone) so I need to copy file as follows:

# cp /usr/share/zoneinfo/Asia/Calcutta /etc/localtime
share|improve this answer
I need time offset. I am not sure how this helps. :( P.S. FreeNAS has read-only file system (embedded version at least). – Josip Medved Aug 20 '09 at 23:15
Time offset IS your timezone...? AFAIK in FreeBSD your system clock should be set to UTC, and then the timezone file tells the OS how to adjust the time to your local time. Thus, to change your local time from +2 to +1 you change the timezone file. – Mark Henderson Aug 21 '09 at 0:04
@Farseeker: While this would work on FreeBSD, FreeNAS stripped bunch of things and made it's file system persistent. Whichever change I make, it will not be persisted across reboots. – Josip Medved Aug 21 '09 at 5:40
@Farseeker: Additionally, these functions do not return me offset as number. And that is what I need. A number. – Josip Medved Aug 21 '09 at 5:41
get_current_timzone() {

CURRENT_TIMEZONE="$(md5 /etc/localtime | awk '{print $4}')"

find /usr/share/zoneinfo | while read LINE; do
    FOUND_TIMEZONE="$(md5 ${LINE} | awk '{print $4}')"
    if [ "${CURRENT_TIMEZONE}" == "${FOUND_TIMEZONE}" ]; then
        echo ${LINE} | sed -E 's|/usr/share/zoneinfo/||'


root@Host-10 [~]$ get_current_timzone
share|improve this answer
For the love of $DEITY why?! – Chris S Feb 17 '14 at 3:28
find /usr/share/zoneinfo/ -type f -exec cmp -s {} /etc/localtime \; -print | awk -F/ -vOFS=/ '{print $5,$6}' – ghoti Mar 27 '14 at 15:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.