Last active
March 21, 2024 15:59
-
-
Save benob/cb71f72f7348aab0f351cc46d10b59d6 to your computer and use it in GitHub Desktop.
Simple time conversion script for a number of time zones in reference to local timezone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# pass date as argument, empty is today | |
ref=$1 | |
# fill this list with timezones you are interested in; first element is reference timezone | |
zones[1]=`cat /etc/timezone` | |
zones[2]="Europe/London" | |
zones[3]="Asia/Calcutta" | |
zones[4]="Asia/Tokyo" | |
zones[5]="America/Los_Angeles" | |
zones[6]="America/Montreal" | |
date -d "$ref" +'%a %D (%Z %:z)' | |
for zone in "${zones[@]}"; do | |
printf "%-11s" `echo $zone|sed 's/.*\///;s/.*\(.\{10\}\)/…\1/'` | |
# show converted time for timeslots from 8am to 5pm | |
for time in `seq 8 17`; do | |
echo -n " "$(TZ=$zone date -d "TZ=\"${zones[1]}\" $ref $time:00" +%H:%M) | |
done | |
# compute and show difference with local timezone | |
diff=$(expr $(printf "%g" `TZ=$zone date +%z`) - $(printf "%g" `date +%z`)|sed 's/..$/:&/;s/^/+/;s/^+-/-/') | |
if [ "$diff" != +0 ]; then | |
echo " ($diff)" | |
else | |
echo | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment