Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripting for time zone

SOLVED
Go to solution
Highlighted
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
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.