Operating System - HP-UX
1833777 Members
1965 Online
110063 Solutions
New Discussion

Re: Shell script to check time

 
yihwen
New Member

Shell script to check time

Anyone out there know or have a sample shell script code written in bash to check the time of other countries? I been looking through the zoneinfo under
/usr/share/lib/zoneinfo but didnt managed to work out.
Hope someone can help me out with this. Thanks
3 REPLIES 3
Paula J Frazer-Campbell
Honored Contributor

Re: Shell script to check time

HI

Have a look at /usr/lib/tztab.

Man tztab


Paula
If you can spell SysAdmin then you is one - anon
Darrell Allen
Honored Contributor

Re: Shell script to check time

As Paula points out, tztab is a list of timezones. Simply set TZ to the desired timezone and then use the date command. You will have to figure out what timezone goes with which country.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
James R. Ferguson
Acclaimed Contributor

Re: Shell script to check time

Hi:

As already pointed out, the definition of the world's various timezones are found in '/usr/lib/tztab'.

If you merely want to find out the date and time for a timezone other than yours, do this:

# date # ...gives your local date and time

To determine what time it is in Moscow, I note from 'usr/lib/tztab' that the timezone should be 'WST-3WSTDST'. Thus:

# TZ=WST-3WSTDST date

..will return Moscow's current time.

Note that I only reset the TZ variable for the duration of the command line. Note the blank (space) between the TZ setting and the 'date' command.

Regards!

...JRF...