Skip to content

Instantly share code, notes, and snippets.

@craigforr
Last active August 31, 2021 15:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save craigforr/d2c6fbee1e5c2a6f8bf82ea00cdaac96 to your computer and use it in GitHub Desktop.
BASH Script to display dates and times for any world time zone
#!/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
@craigforr
Copy link
Author

This works nicely in BASH on Ubuntu on Windows Subsystem for Linux (WSL) on Windows 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment