Showing posts with label Converting Time from PST to IST. Show all posts
Showing posts with label Converting Time from PST to IST. Show all posts

Wednesday, November 27, 2013

Converting Time from PST to IST

Requirement:
I have some monitoring scripts that captures the system statistics at a regular interval and writes it into a Logfile with system time, which is in PST.  When any incident happens during the IST hours, the concern Team in India reports us the problem with IST timing.  As a subsequent action, when I try to analyze the Logfile captured by the system, the timestamp in it was confusing me, as I need to match with IST time-interval that was reported.  So in order to easy my job, I came out with this solution of gathering the system statistics in IST but without changing the Timezone setting on the server.

Solution:
TIME_IN_IST=`TZ='GMT-5:30' date +"%H:%M:%S %D IST"`
echo $TIME_IN_IST

Sample Execution:
[root@linuxhost]# date
Tue Nov 26 20:00:37 PST 2013
[root@linuxhost]# date +"%H:%M:%S %D IST"
20:00:42 11/26/13 IST
[root@linuxhost]# TIME_IN_IST=`TZ='GMT-5:30' date +"%H:%M:%S %D IST"`
[root@linuxhost]# echo $TIME_IN_IST
09:30:46 11/27/13 IST
[root@linuxhost]# date
Tue Nov 26 20:00:54 PST 2013
[root@linuxhost]#

How it works:
I have used GMT offset to match with IST, which is 13.5 hours ahead.  GMT for California is 8 hours behind "GMT-8.00"  and GMT for India is "GMT+5.30".  To match with India Timing, it has to be 13.5 (8+5.30) hours behind.