Timezone in +/-HHMM format

Hey guys,

is thr any easy way of fetching Timezone of the Solaris server in (+/-)HHMM format using shell scripts.

Say, if the current time zone is GMT, the script should return +0000
If the current timezone is Asia/Calcutta in /etc/TIMEZONE, the scripts has to return +0530

Hi
use this command " date +%z "

Hi jagnikam,

Thanks for the reply.
I tried it.
But the output is GMT not +0000

Straight shell does not do what you need. try perl:

#!/bin/ksh

get_tz()
{
perl -e '
     use POSIX;
     ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)=localtime(43200);
     ($sec1, $min1, $hour1, $mday, $mon, $year, $wday, $yday, $isdst)=gmtime(43200);      
     $diffmin=$min - $min1;
     $diff=$hour - $hour1;
     printf "%s%02d%02d\n", ($hour1 <= $hour)?"+":"-", abs($diff), abs($diffmin);
     '
}


mytimezone=$( get_tz)
echo "my time zone is: $mytimezone"

$ /opt/exp/gnu/bin/date +%z
-0500
$ /opt/exp/gnu/bin/date +%Z
EST

Make sure you are using GNU date.

You can reasonably expect a system to support POSIX specifications for the date command. POSIX does not specify a %z. That is a GNU extension. GNU date is a good program, but if he is on a multiuser system, getting GNU date installed may be neither practical nor allowed.

GNU date is clearly not what the OP is now using.