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.

Josip Medved
  • 1,674
  • 2
  • 18
  • 18

3 Answers3

7
$ date "+%Z"

Will give you the current timezone

$ date "+%z"

Will give the offset from DST

Bill Weiss
  • 10,782
  • 3
  • 37
  • 65
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
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
Leander
  • 11
  • 1
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
Mark Henderson
  • 68,316
  • 31
  • 175
  • 255
  • 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 00: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 05: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 05:41