1

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.

3 Answers 3

7
$ date "+%Z"

Will give you the current timezone

$ date "+%z"

Will give the offset from DST

4
  • I tried this already but both of them give me 0. Commented Aug 21, 2009 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. Commented Aug 21, 2009 at 5:37
  • Dang :( No idea, then. How about "echo $TZ" in a terminal?
    – Bill Weiss
    Commented Aug 21, 2009 at 14:28
  • 2
    I suppose "no idea" isn't correct, since I followed that with an idea.
    – Bill Weiss
    Commented Aug 21, 2009 at 14:29
1
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/||'
    fi
done

}


root@Host-10 [~]$ get_current_timzone
3
  • 1
    For the love of $DEITY why?!
    – Chris S
    Commented Feb 17, 2014 at 3:28
  • 1
    find /usr/share/zoneinfo/ -type f -exec cmp -s {} /etc/localtime \; -print | awk -F/ -vOFS=/ '{print $5,$6}'
    – ghoti
    Commented Mar 27, 2014 at 15:27
  • 1
    Or even, get_current_timzone() { cd /usr/share/zoneinfo/ && find * -type f -exec cmp -s {} /etc/localtime \; -print; }
    – ghoti
    Commented Mar 10, 2017 at 16:26
0

FreeNAS runs on FreeBSD, so using http://www.cyberciti.biz/faq/howto-set-date-and-time-timezone-in-freebsd/ 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
4
  • I need time offset. I am not sure how this helps. :( P.S. FreeNAS has read-only file system (embedded version at least). Commented Aug 20, 2009 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. Commented Aug 21, 2009 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. Commented Aug 21, 2009 at 5:40
  • @Farseeker: Additionally, these functions do not return me offset as number. And that is what I need. A number. Commented Aug 21, 2009 at 5:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .