Re: Scripting for time zone (153 Views)
Reply
Regular Advisor
shikhar_1
Posts: 182
Registered: ‎11-18-2010
Message 1 of 3 (153 Views)
Accepted Solution

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.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 3 (153 Views)

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...
Acclaimed Contributor
Dennis Handly
Posts: 25,054
Registered: ‎03-06-2006
Message 3 of 3 (153 Views)

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.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.