Last active
August 31, 2021 15:55
-
-
Save craigforr/d2c6fbee1e5c2a6f8bf82ea00cdaac96 to your computer and use it in GitHub Desktop.
BASH Script to display dates and times for any world time zone
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/sh | |
# Show date and time in other time zones | |
# Source: python - command-line world clock? - Stack Overflow | |
# https://stackoverflow.com/questions/370075/command-line-world-clock | |
function world_date(){ | |
if [ "$1"x != 'x' ]; then | |
search=$1 | |
else | |
echo "Please provide a time zone." | |
fi | |
zoneinfo=/usr/share/zoneinfo/posix/ | |
format='%a %F %T' | |
find -L $zoneinfo -type f \ | |
| grep -i "$search" \ | |
| while read z; do | |
d=$(TZ=$z date +"$format") | |
printf "%-34s %23s\n" ${z#$zoneinfo} "$d" | |
done | |
} | |
world_date $1 | |
# EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works nicely in BASH on Ubuntu on Windows Subsystem for Linux (WSL) on Windows 10.