Operating System - HP-UX
1753262 Members
4897 Online
108792 Solutions
New Discussion юеВ

Re: Scripting for time zone

 
SOLVED
Go to solution
shikhar_1
Regular Advisor

Scripting for time zone

Hi,

Can anyone help in creating a shell script for time zone conversion?

My requirement is that: the script will run on the server and take out the Time Zone (let us suppose it is CDT) and i wanted it to be converted this CDT time(it should always be 1 P.M) in GMT +5:30 through script. Whatever the timing zones of server i just wanted to convert it in GMT +5:30
For Example- the current time on server is 11:00 P.M. CDT so i wanted to know whats the timings in GMT +5:30 when the server timing is 1:00PM CDT, i mean 1 P.M. CDT is equal to what in GMT +5:30 through script.
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: Scripting for time zone

Hi:

# TZ=EST5EDT date

# TZ=UTC date

# TZ=PST8PDT date

...will establish a timezone for the duration of the command line since there is no semicolon (';') after the TZ variable setting.

You can do this in a script and capture the result, too:

# MYTIME=$(TZ=PST8PDT date)
# echo ${MYTIME}

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: Scripting for time zone

JRF has shown you how to convert the current time to IST: TZ=IST-5:30 date

If you want to convert arbitrary times, you'll need to write a C/C++ program or use perl.