The time zone offset from GMT in the Linux shell script

Is there any way to get the offset of a given time zone (type identifier EDT or America / New_York) from GMT in linux shell script?

+7
timezone linux offset
source share
2 answers

Export the TZ environment variable and print date in% z to offset the time domain.

#!/bin/sh export TZ=":Pacific/Auckland" date +%z 
+12
source share

This is a roundabout way to do this, but it works ( freely based on this ):

 #!/bin/bash ZONE=$1 TIME=$(date +%s --utc -d "12:00:00 $ZONE") UTC_TIME=$(date +%s --utc -d "12:00:00") ((DIFF=UTC_TIME-TIME)) echo - | awk -v SECS=$DIFF '{printf "%d",SECS/(60*60)}' 

Save this as tzoffset , make it executable and run it like this:

 tzoffset PST 

This script in its current form handles only reduced time intervals.

+2
source share

All Articles